Skip to content

Fix timezone, stale spot price and diagnostics, JWT decoding and retries - #8

Merged
andreasthell merged 2 commits into
mainfrom
claude/loving-carson-jhqmhn
Sep 23, 2026
Merged

andreasthell merged 2 commits into
mainfrom
claude/loving-carson-jhqmhn

Conversation

@andreasthell

Copy link
Copy Markdown
Owner

Follow-up to #7: fixes the remaining correctness findings (5–10) from the code review.

Changes

  • Swedish dates for revenue and energy totals. Revenue days and the energy totals' year now use Europe/Stockholm, as the spot price already did, instead of the host timezone. HA does not set the process timezone, so a UTC container showed yesterday's revenue between 00:00 and 02:00. The timezone is now shared as API_TZ in const.py.
  • Spot price no longer goes stale. A slot is valid until the next one starts; the last one is assumed to be as long as the one before it (15 min by default). An outdated price list now yields unknown instead of its last price forever. Entries without a Value are skipped instead of raising KeyError, which used to fail the whole refresh because slot selection runs every cycle.
  • JWT expiry is decoded with urlsafe_b64decode. b64decode drops - and _, so payloads containing them always fell back to the 10-minute default expiry.
  • Logbook seeding uses the newest timestamp among the entries. If the newest line had no timestamp, the seed stayed None and logbook events never fired.
  • Outdated CM10 diagnostics are reported as unknown. Current in connectionStatus is the CM10's latest report, however old. Reports older than 3 hours (DIAG_MAX_AGE), or missing ones, now clear battery temperature and internet connection instead of showing the last state indefinitely. The limit is generous because a healthy site's report can be over an hour old (see docs/api.md).
  • Failed slow updates are retried after 5 minutes instead of waiting their full interval (up to 4 hours for news). The six last-update timestamps are replaced by one next-due map.

The version is bumped to 1.5.2.

Tests

  • New tests for each fix: test_coordinator.py (Swedish dates, retry, logbook seeding, diagnostics age), test_spot_price.py (slot validity, hourly slots, missing values) and a new test_api.py (JWT expiry).
  • test_after_last_slot asserted the old behaviour (the last price still shown 22 hours later), so it is replaced by tests for the new behaviour.
  • All 86 tests pass. The new tests fail against the previous code. ruff check and ruff format --check are clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Tt2YacbPwiWKinpfhCss29


Generated by Claude Code

- Revenue dates and the energy totals' year use Swedish local time
  (Europe/Stockholm) like the spot price already did, instead of the host
  timezone. HA does not set the process timezone, so a UTC container got
  yesterday's revenue between 00:00 and 02:00.
- Spot price: a slot is only valid until the next one starts (the last
  one as long as the one before it), so an outdated price list yields
  unknown instead of its last price forever. Entries without a Value are
  skipped instead of raising KeyError and failing the whole refresh.
- JWT expiry is decoded with urlsafe_b64decode. b64decode dropped "-"
  and "_", so payloads containing them always fell back to 10 minutes.
- The logbook is seeded with the newest timestamp among its entries, so
  a newest line without a timestamp no longer disables logbook events.
- CM10 diagnostics older than 3 hours, or missing, are reported as
  unknown instead of showing the last connection state indefinitely.
- A failed slow update is retried after 5 minutes instead of waiting its
  full interval (up to 4 hours for news). The six last-update timestamps
  are replaced by one next-due map.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tt2YacbPwiWKinpfhCss29
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tt2YacbPwiWKinpfhCss29
@andreasthell
andreasthell merged commit 11d003d into main Sep 23, 2026
3 checks passed
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.

2 participants