This commit is contained in:
2025-07-31 19:16:08 -06:00
parent a83f0d0937
commit c23d99726d

View File

@@ -105,11 +105,13 @@ async def monitor_garage_door(app):
except asyncio.TimeoutError:
logging.warning("Request to camera timed out.")
PREDICTION_HISTORY.append('unknown')
if len(PREDICTION_HISTORY) > PREDICTION_HISTORY_MAX_LENGTH:
PREDICTION_HISTORY.pop(0)
except aiohttp.ClientError as e:
logging.error(f"Client error during image fetch: {e}")
PREDICTION_HISTORY.append('unknown')
if len(PREDICTION_HISTORY) > PREDICTION_HISTORY_MAX_LENGTH:
PREDICTION_HISTORY.pop(0)
@@ -130,11 +132,13 @@ async def handle_root(request):
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):