comparison light_bridge.py @ 25:cee43f550577

add /lightNames
author drewp@bigasterisk.com
date Fri, 02 Feb 2024 20:52:09 -0800
parents e3dbd04dab96
children 32cfefe3155b
comparison
equal deleted inserted replaced
24:ecbbf76318bb 25:cee43f550577
27 light = lights.byName(request.query_params['light']) 27 light = lights.byName(request.query_params['light'])
28 body = (await request.body()).decode('utf8') 28 body = (await request.body()).decode('utf8')
29 await light.setColor(Color.fromHex(body)) 29 await light.setColor(Color.fromHex(body))
30 return JSONResponse(light.to_dict()) 30 return JSONResponse(light.to_dict())
31 31
32 async def lightNames(lights: Lights, request: Request) -> JSONResponse:
33 return JSONResponse({'lightNames': lights.allNames()})
34
32 35
33 async def table(lights: Lights, req: Request) -> EventSourceResponse: 36 async def table(lights: Lights, req: Request) -> EventSourceResponse:
34 37
35 def updateMessage(): 38 def updateMessage():
36 return json.dumps({'now': time.time()} | lights.to_dict()) 39 return json.dumps({'now': time.time()} | lights.to_dict())
50 lights = Lights(mqtt) 53 lights = Lights(mqtt)
51 graph = PatchableGraph() 54 graph = PatchableGraph()
52 app = Starlette(debug=True, 55 app = Starlette(debug=True,
53 routes=[ 56 routes=[
54 Route('/api/output', partial(output, lights), methods=['PUT']), 57 Route('/api/output', partial(output, lights), methods=['PUT']),
58 Route('/api/lightNames', partial(lightNames, lights), methods=['GET']),
55 Route('/api/table', partial(table, lights)), 59 Route('/api/table', partial(table, lights)),
56 Route('/api/graph', StaticGraph(graph)), 60 Route('/api/graph', StaticGraph(graph)),
57 Route('/api/graph/events', GraphEvents(graph)), 61 Route('/api/graph/events', GraphEvents(graph)),
58 ]) 62 ])
59 63