From dce28197f5b2c813b73027ab6bc9a8b5485471b8 Mon Sep 17 00:00:00 2001 From: cayossarian <23534755+cayossarian@users.noreply.github.com> Date: Tue, 10 Mar 2026 17:19:11 -0700 Subject: [PATCH] Normalize negative zero on idle circuit power Circuit power negation (-raw_power_w) produced IEEE 754 -0.0 when the panel reported 0.0 for an idle circuit, causing HA to display -0W instead of 0W. The result is now normalized with `or 0.0`. Fixes SpanPanel/span#185 --- CHANGELOG.md | 6 ++++++ pyproject.toml | 2 +- src/span_panel_api/mqtt/homie.py | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 146b082..30cc8e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.2.4] - 03/2026 + +### Fixed + +- **Negative zero on idle circuits** — Circuit power negation (`-raw_power_w`) produced IEEE 754 `-0.0` when the panel reported `0.0` for an idle circuit. The value is now normalized to positive zero after negation. + ## [2.0.0] - 02/2026 v2.0.0 is a ground-up rewrite. The REST/OpenAPI transport has been removed entirely in favor of MQTT/Homie — the SPAN Panel's native v2 protocol. This is a breaking change: all consumer code must be updated to use the new API surface. diff --git a/pyproject.toml b/pyproject.toml index 33995d1..2f7884f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "span-panel-api" -version = "2.2.2" +version = "2.2.4" description = "A client library for SPAN Panel API" authors = [ {name = "SpanPanel"} diff --git a/src/span_panel_api/mqtt/homie.py b/src/span_panel_api/mqtt/homie.py index 568d202..2fbf5fb 100644 --- a/src/span_panel_api/mqtt/homie.py +++ b/src/span_panel_api/mqtt/homie.py @@ -264,7 +264,7 @@ def _build_circuit(self, node_id: str, device_type: str = "circuit", relative_po # active-power is in watts; negate so positive = consumption raw_power_w = _parse_float(self._get_prop(node_id, "active-power")) - instant_power_w = -raw_power_w + instant_power_w = -raw_power_w or 0.0 # Energy: exported-energy = consumption (panel exports TO circuit) consumed_wh = _parse_float(self._get_prop(node_id, "exported-energy"))