Mercurial > code > home > repos > light-bridge
changeset 25:cee43f550577
add /lightNames
author | drewp@bigasterisk.com |
---|---|
date | Fri, 02 Feb 2024 20:52:09 -0800 |
parents | ecbbf76318bb |
children | 33b3eb24506e |
files | light.py light_bridge.py |
diffstat | 2 files changed, 7 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/light.py Fri Feb 02 20:51:48 2024 -0800 +++ b/light.py Fri Feb 02 20:52:09 2024 -0800 @@ -162,6 +162,9 @@ self.notifyChanged() + def allNames(self) -> list[str]: + return list(self._d.keys()) + def byName(self, name: str) -> Light: return self._d[name]
--- a/light_bridge.py Fri Feb 02 20:51:48 2024 -0800 +++ b/light_bridge.py Fri Feb 02 20:52:09 2024 -0800 @@ -29,6 +29,9 @@ await light.setColor(Color.fromHex(body)) return JSONResponse(light.to_dict()) +async def lightNames(lights: Lights, request: Request) -> JSONResponse: + return JSONResponse({'lightNames': lights.allNames()}) + async def table(lights: Lights, req: Request) -> EventSourceResponse: @@ -52,6 +55,7 @@ app = Starlette(debug=True, routes=[ Route('/api/output', partial(output, lights), methods=['PUT']), + Route('/api/lightNames', partial(lightNames, lights), methods=['GET']), Route('/api/table', partial(table, lights)), Route('/api/graph', StaticGraph(graph)), Route('/api/graph/events', GraphEvents(graph)),