Skip to content

Fix lost events, CM10 event spam, stale revenue and energy resets - #7

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

Fixes the four most serious findings from a code review of the integration. Each one is covered by a test that failed on the previous code.

Changes

  1. Event entities lost events. HA's EventEntity._trigger_event() only stores the event; it is published when the state is written. The entities triggered every new logbook entry or news item and then wrote state once, so when several arrived in one refresh, automations only saw the last. A new _fire() helper writes state after each event (HA 2026.9 keeps the timestamps strictly increasing so each write is a separate state change).
  2. Energy totals could corrupt the Energy dashboard. An empty or partial /datagrouping/series response published 0 (or a lower total). For total_increasing, HA treats a drop below 90 % as a meter reset and counts the next real value as the whole lifetime total again. Empty responses and decreases are now ignored.
  3. The CM10 status event re-fired every 60 s while TestInfo.Latest was missing (e.g. an empty /site/Statuses list). A missing status no longer counts as a change.
  4. Today's revenue kept yesterday's value after midnight until the first entry of the day appeared, because the API omits days without data. It is now 0 in that case, and entries for several services are summed (as the monthly total already did). The active service name keeps its last known value, since it describes enrollment rather than today's earnings.

The README paragraph on decreasing energy sensors now describes the new behaviour, and the version is bumped to 1.5.1.

Tests

  • New tests/test_coordinator.py runs the real CheckwattCoordinator._async_update_data against a fake API client.
  • tests/test_event.py now drives the event entities through _handle_coordinator_update.
  • The HA stubs in conftest.py now mirror HA's publish-on-write behaviour for events.
  • 75 tests pass (9 of the new ones failed on the previous code), and ruff check and ruff format --check are clean.

Known limitation

The energy guard compares with the previous value in memory, so it does not cover the first refresh after an HA restart. An empty response is still ignored then, but a partial one would get through. Covering that needs the sensors to restore their last state.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Tt2YacbPwiWKinpfhCss29


Generated by Claude Code

- Event entities: write state after each triggered event. HA only
  publishes the latest event per state write, so several new logbook
  entries or news items in one refresh dropped all but the last.
- CM10 status: a missing TestInfo.Latest (e.g. empty /site/Statuses) is
  no longer a change, so the event no longer re-fires every cycle.
- Today's revenue: an empty Revenue list (the API omits days without
  data) now means 0 instead of keeping yesterday's value, and entries
  for several services are summed. The service name keeps its last
  known value.
- Energy totals: ignore empty responses and decreases. Publishing 0 or
  a partial total made HA's statistics detect a meter reset and count
  the next value as the whole lifetime total again.

Adds coordinator tests driven by a fake API client and event entity
tests, with HA stubs that mirror EventEntity's publish-on-write
behaviour.

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 145e9af 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