feat: add GET /state handler to return determined state
Co-authored-by: aider (gemini/gemini-2.5-pro-preview-05-06) <aider@aider.chat>
This commit is contained in:
11
server.py
11
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)
|
||||
|
Reference in New Issue
Block a user