Mercurial > code > home > repos > light-bridge
comparison 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 |
comparison
equal
deleted
inserted
replaced
10:140633abfa2a | 11:028ed39aa78f |
---|---|
1 """ | 1 """ |
2 replaces a lot of mqtt_to_rdf and rdf_to_mqtt | 2 replaces a lot of mqtt_to_rdf and rdf_to_mqtt |
3 """ | 3 """ |
4 import asyncio | |
4 import json | 5 import json |
5 import logging | 6 import logging |
6 import time | 7 import time |
7 from functools import partial | 8 from functools import partial |
8 from color import Color | 9 from color import Color |
29 return JSONResponse(light.to_dict()) | 30 return JSONResponse(light.to_dict()) |
30 | 31 |
31 | 32 |
32 async def table(lights: Lights, req: Request) -> EventSourceResponse: | 33 async def table(lights: Lights, req: Request) -> EventSourceResponse: |
33 | 34 |
35 def updateMessage(): | |
36 return json.dumps({'now': time.time()} | lights.to_dict()) | |
37 | |
34 async def g(): | 38 async def g(): |
35 async for ping in lights.changes(): | 39 yield updateMessage() |
36 yield json.dumps({'now': time.time()} | lights.to_dict()) | 40 async for ping in lights.changes(): # broken if there's more than one caller! |
41 log.info('send table event') | |
42 yield updateMessage() | |
43 await asyncio.sleep(.5) # slow down the inf loop | |
37 | 44 |
38 return EventSourceResponse(g()) | 45 return EventSourceResponse(g()) |
39 | 46 |
40 | 47 |
41 def main(): | 48 def main(): |