comparison light_bridge.py @ 14:e3dbd04dab96

add mqtt; talk to first light (no throttling)
author drewp@bigasterisk.com
date Sun, 28 Jan 2024 20:49:42 -0800
parents 028ed39aa78f
children cee43f550577
comparison
equal deleted inserted replaced
13:1c865af058e7 14:e3dbd04dab96
16 from starlette.responses import JSONResponse 16 from starlette.responses import JSONResponse
17 from starlette.routing import Route 17 from starlette.routing import Route
18 from starlette_exporter import PrometheusMiddleware, handle_metrics 18 from starlette_exporter import PrometheusMiddleware, handle_metrics
19 19
20 from light import Lights 20 from light import Lights
21 21 from mqtt_io import MqttIo
22 logging.basicConfig(level=logging.INFO) 22 logging.basicConfig(level=logging.INFO)
23 log = logging.getLogger() 23 log = logging.getLogger()
24 24
25 25
26 async def output(lights: Lights, request: Request) -> JSONResponse: 26 async def output(lights: Lights, request: Request) -> JSONResponse:
44 44
45 return EventSourceResponse(g()) 45 return EventSourceResponse(g())
46 46
47 47
48 def main(): 48 def main():
49 lights = Lights() 49 mqtt = MqttIo()
50 lights = Lights(mqtt)
50 graph = PatchableGraph() 51 graph = PatchableGraph()
51 app = Starlette(debug=True, 52 app = Starlette(debug=True,
52 routes=[ 53 routes=[
53 Route('/api/output', partial(output, lights), methods=['PUT']), 54 Route('/api/output', partial(output, lights), methods=['PUT']),
54 Route('/api/table', partial(table, lights)), 55 Route('/api/table', partial(table, lights)),