✨ feat: site-level total_energy sensors from official QUANTITY/HOUR buckets #71
No reviewers
Labels
No labels
v1.0 · bloquant
v1.0 · majeur
v1.0 · mineur
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
mat/homeassistant-comwatt!71
Loading…
Reference in a new issue
No description provided.
Delete branch "site-total-energy"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Adds the site-level cumulative energy sensors needed to drive the HA Energy dashboard from whole-site figures, fed exclusively by Comwatt's official hourly buckets.
What it adds
6 new sensors per site —
<site>_production_total_energy,_consumption_,_injection_,_withdrawal_,_charge_,_discharge_— withdevice_class: energy,state_class: total_increasing, unit Wh, so they are directly selectable in the Energy dashboard.Where the values come from
get_site_time_series(site_id, "QUANTITY", "HOUR", None, "DAY", 8)— the server's official hourly Wh buckets for the whole site (verified live: 191 buckets over 8 days). Each bucket newer than the site's high-water mark is folded in exactly once.*_powersite sensors and the per-device*_total_energyentities.unknown(never0), which avoids a false 8-day jump in the statistics.Cost and robustness
ENERGY_MIN_FETCH_INTERVAL_S, the same gate cadence as the per-device QUANTITY path. On a gate-closed poll or a failed fetch, the last known totals are republished unchanged.comwatt.energy_statestore under a reserved__sites__key (additive;_STORE_VERSIONstays 1, old stores load cleanly).TOTAL_INCREASINGcontract protected: totals only ever advance, and negative server values are rejected with a warning (corrupt upstream data would otherwise push the counter backwards and break HA statistics).Tests
103 total (93 baseline + 10 new): sensor creation/classes, bucket accumulation across polls, 8-day seeding, restart restore without re-folding, API-failure republication, reserved store key, negative-value rejection, short-series isolation. ruff + mypy clean.
Notes
__init__.pyis untouched: the existing load/save lifecycle (setup, end of poll,FINAL_WRITE, unload) already covers the new site state._delta→_powerinsensor.py); merge #70 first.WIP: feat: site-level total_energy sensors from official QUANTITY/HOUR bucketsto ✨ feat: site-level total_energy sensors from official QUANTITY/HOUR buckets