40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
from decimal import Decimal
|
|
import logging
|
|
|
|
from models import EngineFixture, Flickr
|
|
|
|
|
|
class Engine:
|
|
"""Render a lightshow."""
|
|
|
|
def __init__(self, flickr: Flickr, apis: dict[str, str]) -> None:
|
|
self.time: Decimal = Decimal.from_float(0)
|
|
self.fixtures: dict[str, EngineFixture] = {
|
|
f.id: EngineFixture(f) for s in flickr.spaces for f in s.fixtures
|
|
}
|
|
self.flickr = flickr
|
|
self.apis = apis
|
|
|
|
# Validate fixture APIs
|
|
for id, f in self.fixtures.items():
|
|
if f.fixture.api not in self.apis.keys():
|
|
logging.warning(
|
|
f"Fixture API unknown [{f.fixture.api}]. Fixture will be removed. Fixture ID [{f.fixture.id}]. Known APIs [{', '.join([a for a in self.apis.keys()])}]."
|
|
)
|
|
del self.fixtures[id]
|
|
|
|
def next(self, step_size: Decimal):
|
|
"""Calculate light values for next step in time. Step size in seconds."""
|
|
prev_time = self.time
|
|
self.time += step_size
|
|
|
|
for s in self.flickr.sequences:
|
|
for t in s.tracks:
|
|
# TODO: Calculate new state
|
|
pass
|
|
|
|
def propagate(self):
|
|
"""Forward new fixture states to APIs."""
|
|
for f in self.fixtures.values():
|
|
api = self.apis[f.fixture.api]
|
|
# TODO: Pass update to API
|