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

Exception from set_curfew API (daylight saving change related?) #209

Open
therefromhere opened this issue Apr 6, 2024 · 5 comments
Open

Comments

@therefromhere
Copy link
Contributor

therefromhere commented Apr 6, 2024

Just a heads up in case others hit this - I've been getting an exception from the set_curfew API since daylight saving changed for me today (in NZ, so changing out of daylight saving).

I'll look at adding a workaround, but I think this is a once-a-year issue that will go away in a few hours. I think I had a similar issue this time last year.

I think this is because the Sure API is doing some weird adjustment (possibly a bug) to correct for daylight saving changing. Via the website, if I manually set the curfew end time it's subtracting one hour from the requested end time.

e.g. If via the Sure app, I set Unlock time of 7:39, then it succeeds, but shows time on the website (and via the API data) at 6:39.

PUT https://app-api.production.surehub.io/api/device/123/control

request:

{
	"curfew": [
		{
			"enabled": true,
			"lock_time": "18:05",
			"unlock_time": "07:39"
		}
	]
}

200 response: (note unlock_time)

{
	"data": {
		"curfew": [
			{
				"enabled": true,
				"lock_time": "18:05",
				"unlock_time": "06:39"
			}
		],
		"locking": 0,
		"fast_polling": true
	}
}

I think this is a timezone bug from the backend of the Sure app. Maybe something like it's using midnight of current date (rather than current date-time) to figure out if daylight saving is in effect.

On our side, the issue is that we fail this check, because the response unlock_time doesn't match the request time here:

surepy/surepy/client.py

Lines 375 to 380 in 9806785

# check if the state is correctly updated
if state == desired_state:
return response
# return None
raise SurePetcareError("ERROR (UN)LOCKING DEVICE - PLEASE CHECK IMMEDIATELY!")

Potentially we could change this to a warning.

@therefromhere
Copy link
Contributor Author

therefromhere commented Apr 6, 2024

One thing I'm curious of is what the actual curfew will be - e.g. will the GET value change to "unlock_time": "07:39" tomorrow?

therefromhere added a commit to therefromhere/surepy that referenced this issue Apr 6, 2024
therefromhere added a commit to therefromhere/sureflap_gcloud that referenced this issue Apr 6, 2024
therefromhere added a commit to therefromhere/sureflap_gcloud that referenced this issue Apr 6, 2024
Use my workaround for DST bug

See benleb/surepy#209
@therefromhere
Copy link
Contributor Author

therefromhere commented Apr 7, 2024

The issue is no longer happening, I suspect that's because it's now after midnight UTC, so UTC date has changed.

One thing I'm curious of is what the actual curfew will be - e.g. will the GET value change to "unlock_time": "07:39" tomorrow?

For reference, I think the GET value was the one that would be used, I think the bug is that the PUT value was being incorrectly interpreted (i.e. I don't think the GET value would change), so to properly workaround this bug I'd need to adjust the time I'm setting.

@FirstRulez
Copy link

Not sure if it's connected but I have noticed that (at least for me here in the UK) whenever our local times change my curfew settings for our cat flap the next day show one hour out, and so every time the clocks change I have to remember to log into the Sure app, and fix the settings.

I assume it's because they store them as UTC and then display them as local time, but then the flap enforces them as local time (which makes completely no sense).

Just in case it is of use/interest.

@therefromhere
Copy link
Contributor Author

therefromhere commented Apr 7, 2024

Not sure if it's connected but I have noticed that (at least for me here in the UK) whenever our local times change my curfew settings for our cat flap the next day show one hour out, and so every time the clocks change I have to remember to log into the Sure app, and fix the settings.

I assume it's because they store them as UTC and then display them as local time, but then the flap enforces them as local time (which makes completely no sense).

Just in case it is of use/interest.

Possibly, though worth double checking you have your "Household" timezone to London time and not UTC.

I don't know if the existing time changes for me at DST change, because I have an automated task updating the curfew times to match dawn/dusk every Sunday AM.

FWIW there was a notification in the app "Clock change in your region? You may need to adjust curfew times" which suggests the backend implementation makes no sense like you suggested haha.

@FirstRulez
Copy link

Possibly, though worth double checking you have your "Household" timezone to London time and not UTC.

Thanks for the pointer. I have checked and it is set to what I think is the right setting:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants