Mercurial > code > home > repos > light-bridge
changeset 5:7eeda7f4f9cd
spell it to_dict, for compat with DataClassJsonMixin
author | drewp@bigasterisk.com |
---|---|
date | Sun, 28 Jan 2024 16:01:43 -0800 |
parents | e8e4fd6d5619 |
children | fc8ed0efcd72 |
files | light.py light_bridge.py |
diffstat | 2 files changed, 8 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/light.py Sun Jan 28 16:01:00 2024 -0800 +++ b/light.py Sun Jan 28 16:01:43 2024 -0800 @@ -1,8 +1,9 @@ - import asyncio import logging from dataclasses import dataclass +from color import Color + log = logging.getLogger('light') @@ -16,7 +17,7 @@ colorCurrent: Color latencyMs: float - def to_js(self): + def to_dict(self): return { 'light': { 'name': self.name, @@ -42,7 +43,7 @@ async def changes(self): # yields None on any data change while True: yield None - await asyncio.sleep(1) + await asyncio.sleep(1) # todo - def to_js(self): - return {'lights': [d.to_js() for d in sorted(self._d.values(), key=lambda r: r.name)]} + def to_dict(self): + return {'lights': [d.to_dict() for d in sorted(self._d.values(), key=lambda r: r.name)]}
--- a/light_bridge.py Sun Jan 28 16:01:00 2024 -0800 +++ b/light_bridge.py Sun Jan 28 16:01:43 2024 -0800 @@ -27,14 +27,14 @@ async def output(lights: Lights, request: Request) -> JSONResponse: light = lights.byName(request.query_params['light']) - return JSONResponse(light.to_js()) + return JSONResponse(light.to_dict()) async def table(lights: Lights, req: Request) -> EventSourceResponse: async def g(): async for ping in lights.changes(): - yield json.dumps({'now': time.time()} | lights.to_js()) + yield json.dumps({'now': time.time()} | lights.to_dict()) return EventSourceResponse(g())