Add per-charger energy statistics feed for Energy Dashboard - #416
Open
rhammen wants to merge 1 commit into
Open
Conversation
The live Energy Meter sensor is polling-delayed, so energy lands in the wrong hour on the Energy Dashboard (custom-components#300, also custom-components#162). This adds a separate long-term-statistics feed per charger, backfilled from Zaptec's archived charge sessions and imported hourly, so historical consumption is attributed to the correct hour. - ZaptecStatisticsCoordinator imports /api/sessions/archived into HA external statistics as zaptec:energy_<id>, shown in the Energy Dashboard device picker as "<charger> Energy". - Recorder is an after_dependency; if it is disabled the integration still loads and only this feed is skipped. - Requires the Owner role (the endpoint is Owner-only); a 403 degrades just this feed with a warning, not the whole integration. - Backfills up to 730 days on first run, then imports hourly. Because it is built from completed sessions, the most recent hour or two can lag - it is for accurate historical graphs, not real-time monitoring. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Implements feature #300.
The live Energy Meter sensor is polling-delayed, so energy lands in the wrong hour on the Energy Dashboard (see #300, also #162). This adds a separate long-term-statistics feed per charger, backfilled from Zaptec's archived charge sessions and imported hourly, so historical consumption is attributed to the correct hour.
ZaptecStatisticsCoordinator(statistics.py) imports/api/sessions/archivedinto HA external statistics aszaptec:energy_<id>, shown in the Energy Dashboard device picker as " Energy".after_dependency: if the recorder is disabled the integration still loads, only this feed is skipped.Because it is built from completed sessions, the most recent hour or two can lag — it's for accurate historical graphs, not real-time (the live sensor still covers that).
Tests cover the bucketing logic and the archived-sessions request. Full harness-based coordinator tests will follow once the test-framework migration (#414) lands.
This was written with AI assistance; I have personally reviewed the code. I've also tried to trim the docstrings/comments down in line with maintainer preference — happy to cut further if any still read as too verbose.