✨ fix: convert kWh QUANTITY/HOUR buckets to Wh at reconciliation #64
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/reconcile-convert-kwh"
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?
Slice 2 of 2 — stacks on #63 (
fix/reconcile-skip-unreliable). Review the combined diff againstmainas the complete unit-aware reconciliation fix.Context
Slice 1 made the hourly reconciliation skip
QUANTITY/HOURbuckets whose unit cannot be trusted (kWh, no live reference, incoherent ratio). That stopped the hundred-Wh downward jumps but left grid devices (injection/soutirage) with no drift correction — skipped every hour. This slice adds the kWh→Wh conversion so those grid devices get a bounded drift correction too.The Comwatt endpoint returns mixed units per device with no unit field and no metadata predictor (confirmed — see slice 1's docstring). The unit is inferred from the ratio of the server value to the live ∫W·dt for the hour: a Wh device lands near ratio 1.0, a kWh device near 0.001. Slice 2 adds the kWh ratio band
[0.0005, 0.002]to_server_bucket_to_wh: a bucket in that band is converted×1000to Wh before reconciling. Everything outside both bands is still skipped (slice 1's safety net stays intact).Impact
soutirage 13.23case) now reconcile correctly instead of being skipped: server kWh is converted to Wh and snapped against the live ∫W·dt as a bounded drift correction (a few Wh), never a hundred-Wh unit-conversion jump._server_bucket_to_wh); this slice only extends the helper with a second ratio band + its docstring.stream.pyare untouched.Considerations
[0.0005, 0.002]is centered on 0.001 with the same ~0.5×–2× relative tolerance as the Wh band, and is separated from it by a 250× gap(0.002, 0.5)that serves as the deliberate "incoherent ratio → skip" region. No overlap, no ambiguous boundary.62.83bucket) still fall outside both bands and are skipped — drift uncorrected for those, which is safer than a wrong snap.Tests
80/80 passing,ruffclean,mypyclean.Box verification (live, ~2h15m across multiple hourly reconcile cycles)
Deployed slices 1+2 to the HA box and monitored the
*_total_energysensors every 2 min through several real reconciliation cycles (~20:34 and ~21:29 UTC). Result:WIP: ✨ fix: convert kWh QUANTITY/HOUR buckets to Wh at reconciliationto ✨ fix: convert kWh QUANTITY/HOUR buckets to Wh at reconciliation523d4dd148ff994eed9e