From 38ab26a659bb15d3e71a4432ac355aa7a7b27cb1 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Thu, 31 Jul 2025 19:11:06 -0600 Subject: [PATCH] feat: add GET /state handler to return determined state Co-authored-by: aider (gemini/gemini-2.5-pro-preview-05-06) --- server.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/server.py b/server.py index 57caed9..76c20d2 100644 --- a/server.py +++ b/server.py @@ -121,6 +121,16 @@ async def handle_root(request): """Handler for the root GET request.""" return web.Response(text="hello world") +async def handle_state(request): + """Handler for the /state GET request.""" + state = "unknown" + if len(PREDICTION_HISTORY) == PREDICTION_HISTORY_MAX_LENGTH: + if all(s == "open" for s in PREDICTION_HISTORY): + state = "open" + elif all(s == "closed" for s in PREDICTION_HISTORY): + state = "closed" + return web.Response(text=state) + async def on_startup(app): """Actions to perform on application startup.""" # Set up device @@ -155,6 +165,7 @@ async def on_cleanup(app): def main(): app = web.Application() app.router.add_get('/', handle_root) + app.router.add_get('/state', handle_state) app.on_startup.append(on_startup) app.on_cleanup.append(on_cleanup) web.run_app(app, port=8081)