Repository navigation
Fix lost events, CM10 event spam, stale revenue and energy resets - #7
Merged
Merged
Conversation
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
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)./datagrouping/seriesresponse published0(or a lower total). Fortotal_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.TestInfo.Latestwas missing (e.g. an empty/site/Statuseslist). A missing status no longer counts as a change.0in 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
tests/test_coordinator.pyruns the realCheckwattCoordinator._async_update_dataagainst a fake API client.tests/test_event.pynow drives the event entities through_handle_coordinator_update.conftest.pynow mirror HA's publish-on-write behaviour for events.ruff checkandruff format --checkare 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