Fix GE Cloud Direct EVC API 422 errors after BST clock change#3738
Fix GE Cloud Direct EVC API 422 errors after BST clock change#3738springfall2008 merged 3 commits intomainfrom
Conversation
Use .astimezone(timezone.utc) when formatting EVC API timestamps to ensure UTC times are always sent, regardless of local timezone (BST). Also add tests to verify the UTC conversion for BST scenarios. Agent-Logs-Url: https://github.com/springfall2008/batpred/sessions/cd2904db-aeff-40a0-a66e-30a01f9aca0a Co-authored-by: springfall2008 <48591903+springfall2008@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes GivEnergy GE Cloud Direct EVC API request timestamps after the UK clock change to BST (UTC+1) by ensuring timestamps formatted with a trailing Z are actually UTC (preventing 422 “unprocessable entity” errors from the EVC API, which expects GMT/UTC times).
Changes:
- Convert
now_utc_exactto UTC via.astimezone(timezone.utc)before generatingstart_time/end_timefor EVC sessions and device data requests. - Update GE Cloud tests to use timezone-aware
now_utc_exactmocks and add BST-specific scenarios asserting the API receives UTCZtimestamps.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| apps/predbat/gecloud.py | Ensures EVC start_time/end_time query parameters are derived from a UTC datetime when formatting with Z. |
| apps/predbat/tests/test_ge_cloud.py | Makes mocked times timezone-aware and adds BST coverage to prevent regressions around DST transitions. |
| Get list of EVC sessions | ||
| """ | ||
| now = self.now_utc_exact | ||
| now = self.now_utc_exact.astimezone(timezone.utc) |
There was a problem hiding this comment.
I believe there is a pattern of using now_local. IMO these variables that have a suffix of _utc would be better if they were renamed to _local suffix.
It's hard to understand this line since one would expect the self.now_utc_exact to already be in UTC timezone.
There was a problem hiding this comment.
Rather confusingly the UTC refers to TZ aware formats and not UTC time
After clocks move to BST (UTC+1),
now_utc_exactreturns local time but timestamps were formatted with aZsuffix (UTC), sending times 1 hour ahead to the GivEnergy EVC API — causing 422 errors. The EVC device always operates on GMT regardless of local clock.Changes
gecloud.py: Convertnow_utc_exactto UTC via.astimezone(timezone.utc)before formatting timestamps inasync_get_evc_device_dataandasync_get_evc_sessionstests/test_ge_cloud.py: Updated mock_now_utc_exactto be timezone-aware; added BST test scenarios verifying the API receives UTC times whennow_utc_exactis in BST (UTC+1)Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
api.octopus.energy/home/REDACTED/work/batpred/batpred/coverage/venv/bin/python3 python3 ../apps/predbat/unit_test.py --quick(dns block)gitlab.com/usr/lib/git-core/git-remote-https /usr/lib/git-core/git-remote-https origin REDACTED(dns block)https://api.github.com/repos/springfall2008/batpred/contents/apps/predbat/home/REDACTED/work/batpred/batpred/coverage/venv/bin/python3 python3 ../apps/predbat/unit_test.py --test ge_cloud(http block)/home/REDACTED/work/batpred/batpred/coverage/venv/bin/python3 python3 ../apps/predbat/unit_test.py --quick(http block)If you need me to access, download, or install something from one of these locations, you can either: