🐛 fix: site flow metrics are instantaneous power (W), not hourly Wh #70
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!70
Loading…
Reference in a new issue
No description provided.
Delete branch "fix-site-unit"
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?
Corrects a unit-semantics bug dating from the origin of the site sensors.
The bug
The 6 site sensors (
production,consumption,injection,withdrawal,charge,discharge) were declaredWATT_HOUR/MEASUREMENTon the belief thatget_site_time_series(site_id, "FLOW", "NONE", None, "HOUR", 1)returns hourly Wh deltas (per the code comment and the original analysis in #42).Live API verification (2026-08-15) proved otherwise:
*_powersensors (site production 4507 whilesolaire..._power= 4457 W, same freshness)withdrawal_rate)So these sensors have been instantaneous watts mislabeled as Wh all along. The ~1h "delay" attributed to them in #42 was a misreading — they are ~2 min fresh.
The fix
Metadata-only: the 6 sensors now expose
UnitOfPower.WATT+device_class=POWER(state_class=MEASUREMENTunchanged). Nounique_id, entity_id, name, data source, or cadence change. The false module comment and docstrings are corrected.Migration note (important for HA ≥ 2025.12)
Home Assistant will raise a
units_changedrepair item for these 6 entities and will not record long-term statistics until the old Wh statistics are deleted (Developer Tools → Statistics). Historical states are kept. This is the standard remediation for a mislabeled unit.Tests
2 new (TDD RED→GREEN):
test_site_power_metrics_have_power_unit(unit W, device_class power, value passthrough) andtest_site_rates_still_percent(rates keep % and ×100). 95 tests total, ruff + mypy clean.Relation to #42
Closes the "site sensors lag ~1h" misconception; the real-time site energy work (adding
<site>_*_total_energyfrom the official QUANTITY/HOUR buckets) is the next slice.WIP: fix: site flow metrics are instantaneous power (W), not hourly Whto 🐛 fix: site flow metrics are instantaneous power (W), not hourly Wh