Implemented hue API interface
This commit is contained in:
parent
1ff76c27b2
commit
8323c7a4be
3 changed files with 46 additions and 9 deletions
|
@ -4,20 +4,18 @@ import math
|
||||||
|
|
||||||
from models import (
|
from models import (
|
||||||
EngineFixture,
|
EngineFixture,
|
||||||
EngineKeyframe,
|
|
||||||
EngineTrack,
|
EngineTrack,
|
||||||
Flickr,
|
Flickr,
|
||||||
|
FlickrApiInterface,
|
||||||
Interpolation,
|
Interpolation,
|
||||||
Keyframe,
|
|
||||||
KeyframeValue,
|
KeyframeValue,
|
||||||
Parameter,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class Engine:
|
class Engine:
|
||||||
"""Render a lightshow."""
|
"""Render a lightshow."""
|
||||||
|
|
||||||
def __init__(self, flickr: Flickr, apis: dict[str, str]) -> None:
|
def __init__(self, flickr: Flickr, apis: dict[str, FlickrApiInterface]) -> None:
|
||||||
self.apis = apis
|
self.apis = apis
|
||||||
self.flickr = flickr
|
self.flickr = flickr
|
||||||
self.tracks: list[EngineTrack] = []
|
self.tracks: list[EngineTrack] = []
|
||||||
|
@ -90,7 +88,7 @@ class Engine:
|
||||||
"""Forward new fixture states to APIs."""
|
"""Forward new fixture states to APIs."""
|
||||||
for f in self.fixtures.values():
|
for f in self.fixtures.values():
|
||||||
api = self.apis[f.fixture.api]
|
api = self.apis[f.fixture.api]
|
||||||
# TODO: Pass update to API
|
api.update_fixture(f)
|
||||||
|
|
||||||
def get_current_value(self, track: EngineTrack) -> KeyframeValue:
|
def get_current_value(self, track: EngineTrack) -> KeyframeValue:
|
||||||
"""Interpolate between current keyframes of track and return the interpolated value."""
|
"""Interpolate between current keyframes of track and return the interpolated value."""
|
||||||
|
|
33
src/hue.py
Normal file
33
src/hue.py
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
import logging
|
||||||
|
from models import Capabilities, EngineFixture, FlickrApiInterface
|
||||||
|
from phue import Bridge
|
||||||
|
|
||||||
|
|
||||||
|
class HueApi(FlickrApiInterface):
|
||||||
|
def __init__(self, ip: str) -> None:
|
||||||
|
super().__init__()
|
||||||
|
self.bridge = Bridge(ip)
|
||||||
|
self.bridge.connect()
|
||||||
|
|
||||||
|
def update_fixture(self, fixture: EngineFixture) -> bool:
|
||||||
|
command = {
|
||||||
|
"on": bool(fixture.on),
|
||||||
|
"transitiontime": int(fixture.transition * 10),
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set values based on capabilities
|
||||||
|
if fixture.fixture.capabilities in [
|
||||||
|
Capabilities.BRIGHTNESS,
|
||||||
|
Capabilities.COLOR,
|
||||||
|
Capabilities.TEMPERATURE,
|
||||||
|
]:
|
||||||
|
command["bri"] = fixture.brightness * 255
|
||||||
|
if fixture.fixture.capabilities in [Capabilities.COLOR]:
|
||||||
|
command["sat"] = fixture.brightness * 255
|
||||||
|
command["hue"] = fixture.hue * 65535
|
||||||
|
if fixture.fixture.capabilities in [Capabilities.TEMPERATURE]:
|
||||||
|
command["ct"] = fixture.temperature
|
||||||
|
|
||||||
|
# Apply update
|
||||||
|
self.bridge.set_light(fixture.fixture.api_id, command)
|
||||||
|
return True
|
|
@ -87,16 +87,16 @@ class EngineFixture:
|
||||||
"""On state."""
|
"""On state."""
|
||||||
|
|
||||||
brightness: float = 0
|
brightness: float = 0
|
||||||
"""Brightness state."""
|
"""Brightness state. [0, 1]"""
|
||||||
|
|
||||||
hue: float = 0
|
hue: float = 0
|
||||||
"""Hue state."""
|
"""Hue state. [0, 1]"""
|
||||||
|
|
||||||
saturation: float = 0
|
saturation: float = 0
|
||||||
"""Saturation state."""
|
"""Saturation state. [0, 1]"""
|
||||||
|
|
||||||
temperature: float = 0
|
temperature: float = 0
|
||||||
"""Temperature state."""
|
"""Temperature state, in Kelvin."""
|
||||||
|
|
||||||
transition: float = 0
|
transition: float = 0
|
||||||
"""Transition time in seconds."""
|
"""Transition time in seconds."""
|
||||||
|
@ -298,6 +298,12 @@ class Flickr:
|
||||||
return Flickr.schema().loads(json) # type: ignore
|
return Flickr.schema().loads(json) # type: ignore
|
||||||
|
|
||||||
|
|
||||||
|
class FlickrApiInterface:
|
||||||
|
def update_fixture(self, fixture: EngineFixture) -> bool:
|
||||||
|
"""Update fixture state in API. Returns true if successful."""
|
||||||
|
raise NotImplementedError("'update_fixture' not yet implemented.")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# Small test
|
# Small test
|
||||||
f = Flickr(
|
f = Flickr(
|
||||||
|
|
Loading…
Reference in a new issue