From c8973ea008444186e8a6c1116ff8c5c06e58544f Mon Sep 17 00:00:00 2001 From: John Carter Date: Sun, 7 Apr 2024 10:21:53 +1200 Subject: [PATCH] Add workaround to odd curfew API response See https://github.com/benleb/surepy/issues/209 --- surepy/client.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/surepy/client.py b/surepy/client.py index 8ac750c..83269f4 100644 --- a/surepy/client.py +++ b/surepy/client.py @@ -11,7 +11,7 @@ import asyncio import logging -from datetime import datetime, time +from datetime import datetime, time, timedelta from http import HTTPStatus from http.client import HTTPException from logging import Logger @@ -407,6 +407,21 @@ async def set_curfew( # check if the state is correctly updated if state == desired_state: return response + else: + bugged_unlock_time = unlock_time.replace(unlock_time.hour - 1) + + bug_state = [{ + "lock_time": lock_time.strftime("%H:%M"), + "unlock_time": bugged_unlock_time.strftime("%H:%M"), + "enabled": True, + }] + + if state == bug_state: + # known issue, don't raise exception + logger.warning("unlock_hour off by one - set %s, got %s (see https://github.com/benleb/surepy/issues/209)", desired_state, state) + return response + + logger.error("Error setting curfew, set %s, got %s", desired_state, state) # return None raise SurePetcareError("ERROR SETTING CURFEW - PLEASE CHECK IMMEDIATELY!")