Mercurial > code > home > repos > light-bridge
diff light_bridge.py @ 11:028ed39aa78f
more ts types; attempted multiplayer but the change events are managed wrong
author | drewp@bigasterisk.com |
---|---|
date | Sun, 28 Jan 2024 17:31:06 -0800 |
parents | 140633abfa2a |
children | e3dbd04dab96 |
line wrap: on
line diff
--- a/light_bridge.py Sun Jan 28 16:53:35 2024 -0800 +++ b/light_bridge.py Sun Jan 28 17:31:06 2024 -0800 @@ -1,6 +1,7 @@ """ replaces a lot of mqtt_to_rdf and rdf_to_mqtt """ +import asyncio import json import logging import time @@ -31,9 +32,15 @@ async def table(lights: Lights, req: Request) -> EventSourceResponse: + def updateMessage(): + return json.dumps({'now': time.time()} | lights.to_dict()) + async def g(): - async for ping in lights.changes(): - yield json.dumps({'now': time.time()} | lights.to_dict()) + yield updateMessage() + async for ping in lights.changes(): # broken if there's more than one caller! + log.info('send table event') + yield updateMessage() + await asyncio.sleep(.5) # slow down the inf loop return EventSourceResponse(g())