Mercurial > code > home > repos > light-bridge
comparison light_bridge.py @ 1:42a494b8ee1a
show report time
author | drewp@bigasterisk.com |
---|---|
date | Sun, 28 Jan 2024 15:43:54 -0800 |
parents | 5a77696c6dab |
children | c6fd04e07db0 |
comparison
equal
deleted
inserted
replaced
0:5a77696c6dab | 1:42a494b8ee1a |
---|---|
4 import asyncio | 4 import asyncio |
5 from dataclasses import dataclass | 5 from dataclasses import dataclass |
6 from functools import partial | 6 from functools import partial |
7 import json | 7 import json |
8 import logging | 8 import logging |
9 import time | |
9 | 10 |
10 import background_loop | 11 import background_loop |
11 from patchablegraph import PatchableGraph | 12 from patchablegraph import PatchableGraph |
12 from patchablegraph.handler import GraphEvents, StaticGraph | 13 from patchablegraph.handler import GraphEvents, StaticGraph |
13 from rdflib import Namespace | 14 from rdflib import Namespace |
79 | 80 |
80 async def table(lights: Lights, req: Request) -> EventSourceResponse: | 81 async def table(lights: Lights, req: Request) -> EventSourceResponse: |
81 | 82 |
82 async def g(): | 83 async def g(): |
83 async for ping in lights.changes(): | 84 async for ping in lights.changes(): |
84 yield json.dumps(lights.to_js()) | |
85 await asyncio.sleep(1) | 85 await asyncio.sleep(1) |
86 yield json.dumps({'now': time.time()} | lights.to_js()) | |
86 | 87 |
87 return EventSourceResponse(g()) | 88 return EventSourceResponse(g()) |
88 | 89 |
89 | 90 |
90 def main(): | 91 def main(): |