# HG changeset patch # User drewp@bigasterisk.com # Date 1706500954 28800 # Node ID 7cc004eafb82389a38e8271e6e0cc1754a8a428d # Parent 028ed39aa78fa91d7bde9fdcc6b9012d8aa05bc8 refactor (approx) diff -r 028ed39aa78f -r 7cc004eafb82 light.py --- a/light.py Sun Jan 28 17:31:06 2024 -0800 +++ b/light.py Sun Jan 28 20:02:34 2024 -0800 @@ -68,7 +68,6 @@ class Lights: _d: dict[str, Light] = {} - _changeSleepTask: asyncio.Task | None = None def __init__(self): self.add(Light('do-desk', 'topic1')) @@ -83,6 +82,12 @@ def byName(self, name: str) -> Light: return self._d[name] + def to_dict(self): + return {'lights': [d.to_dict() for d in sorted(self._d.values(), key=lambda r: r.name)]} + + # the following is bad. Get a better events lib. + _changeSleepTask: asyncio.Task | None = None + async def changes(self): # yields None on any data change while True: log.info('Lights has a change') @@ -101,6 +106,3 @@ log.info('Lights.notifyChanged()') if self._changeSleepTask is not None: self._changeSleepTask.cancel() - - def to_dict(self): - return {'lights': [d.to_dict() for d in sorted(self._d.values(), key=lambda r: r.name)]} diff -r 028ed39aa78f -r 7cc004eafb82 src/main.ts --- a/src/main.ts Sun Jan 28 17:31:06 2024 -0800 +++ b/src/main.ts Sun Jan 28 20:02:34 2024 -0800 @@ -75,15 +75,6 @@

Light-bridge

- - - - - - - - - ${this.lights.map( (d: Light) => html` @@ -100,6 +91,7 @@ ` )} + ${this.renderLightHeaders()} ${this.lights.map(this.renderLightRow.bind(this))}
lightaddressrequested colorrequested device coloremitting coloronlinelatency

Updated ${this.reportTime.toLocaleString("sv")}

@@ -109,6 +101,18 @@ `; } + + renderLightHeaders() { + return html` + light + address + requested color + requested device color + emitting color + online + latency + `; + } async onRequestingColor(lightName: string, ev: InputEvent) { const currentRequest = this.lightByName.get(lightName)!.requestingColor; const value = (ev.target as HTMLInputElement).value;