Skip to content

Fix GE Cloud Direct EVC API 422 errors after BST clock change#3738

Merged
springfall2008 merged 3 commits intomainfrom
copilot/fix-ge-cloud-direct-evc-data
Apr 5, 2026
Merged

Fix GE Cloud Direct EVC API 422 errors after BST clock change#3738
springfall2008 merged 3 commits intomainfrom
copilot/fix-ge-cloud-direct-evc-data

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 4, 2026

After clocks move to BST (UTC+1), now_utc_exact returns local time but timestamps were formatted with a Z suffix (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: Convert now_utc_exact to UTC via .astimezone(timezone.utc) before formatting timestamps in async_get_evc_device_data and async_get_evc_sessions
# Before — formats BST time but appends Z (meaning UTC)
now = self.now_utc_exact

# After — always sends correct UTC value
now = self.now_utc_exact.astimezone(timezone.utc)
  • tests/test_ge_cloud.py: Updated mock _now_utc_exact to be timezone-aware; added BST test scenarios verifying the API receives UTC times when now_utc_exact is 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
    • Triggering command: /home/REDACTED/work/batpred/batpred/coverage/venv/bin/python3 python3 ../apps/predbat/unit_test.py --quick (dns block)
  • gitlab.com
    • Triggering command: /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
    • Triggering command: /home/REDACTED/work/batpred/batpred/coverage/venv/bin/python3 python3 ../apps/predbat/unit_test.py --test ge_cloud (http block)
    • Triggering command: /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:

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>
Copilot AI changed the title [WIP] Fix GE Cloud Direct failing to pull GivEnergy EVC data Fix GE Cloud Direct EVC API 422 errors after BST clock change Apr 4, 2026
Copilot AI requested a review from springfall2008 April 4, 2026 15:25
@springfall2008 springfall2008 marked this pull request as ready for review April 4, 2026 17:02
Copilot AI review requested due to automatic review settings April 4, 2026 17:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_exact to UTC via .astimezone(timezone.utc) before generating start_time/end_time for EVC sessions and device data requests.
  • Update GE Cloud tests to use timezone-aware now_utc_exact mocks and add BST-specific scenarios asserting the API receives UTC Z timestamps.

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.

Comment thread apps/predbat/gecloud.py
Get list of EVC sessions
"""
now = self.now_utc_exact
now = self.now_utc_exact.astimezone(timezone.utc)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather confusingly the UTC refers to TZ aware formats and not UTC time

@springfall2008 springfall2008 merged commit 105e484 into main Apr 5, 2026
1 check passed
@springfall2008 springfall2008 deleted the copilot/fix-ge-cloud-direct-evc-data branch April 5, 2026 14:57
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

Successfully merging this pull request may close these issues.

GE Cloud Direct failing to pull GivEnergy EVC data after clocks moved to BST

4 participants