Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround to odd curfew API response #210

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion surepy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!")
Expand Down
Loading