Skip to content

fix: battery power sign, negative zero, and net energy dip consistency#186

Merged
cayossarian merged 6 commits intomainfrom
sign_fixes
Mar 11, 2026
Merged

fix: battery power sign, negative zero, and net energy dip consistency#186
cayossarian merged 6 commits intomainfrom
sign_fixes

Conversation

@cayossarian
Copy link
Member

Summary

  • Battery power sign inverted — Negate battery power sensor to match HA convention (positive = discharging), consistent with existing PV treatment. ([bug?] Battery power is negated? #184)
  • Idle circuits showing -0W — Normalize IEEE 754 negative zero to positive zero on all negated power sensors (PV circuits, battery, PV power). (Change from <2.x - Circuts with no draw reporting as negative / -0W vs 0W before #185)
  • Net energy inconsistent with dip-compensated consumed/produced — Net energy now reads dip offsets from sibling consumed/produced sensors so the value always equals compensated consumed minus compensated produced.
  • Bump span-panel-api to >=2.2.4 — Picks up the API-layer negative-zero fix for circuit power.

Test plan

  • Verify battery power sensor shows negative when charging, positive when discharging
  • Verify idle PV circuits and battery show 0W not -0W
  • Verify net energy equals consumed minus produced when dip compensation is enabled
  • CI passes

The panel reports battery power from its own perspective (positive =
charging), but HA energy cards expect positive = discharging. Negate
the value to align with HA conventions, consistent with how PV power
is already handled.

Fixes #184
Power sensors that negate values (PV circuits, battery, PV power)
could produce IEEE 754 -0.0 when idle, causing HA to display -0W
instead of 0W. All negation sites now normalize zero with `or 0.0`.

Fixes #185
When energy dip compensation is enabled, consumed and produced sensors
apply an offset to the raw value but net energy was computed from raw
snapshot values, causing a visible mismatch. Consumed/produced sensors
now register on the coordinator so net energy can read their offsets
directly and adjust its value to stay consistent.
Reformat ternary lambda in circuit power sensor to match CI ruff
version's preferred style.
Pre-commit was pinned to ruff 0.11.13 while CI used 0.15.1 from
pyproject.toml, causing formatting disagreements on ternary lambdas.
@cayossarian cayossarian merged commit ccf491d into main Mar 11, 2026
7 checks passed
@cayossarian cayossarian deleted the sign_fixes branch March 11, 2026 02:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant