From d7b42980927c31773bda65a926078906c1f82ebf Mon Sep 17 00:00:00 2001 From: glenn schrooyen Date: Sun, 15 Nov 2026 16:05:19 +0100 Subject: [PATCH] EV-03 review: one power-unit table for the probe and the reading POWER_UNITS is now derived from _W_PER, so the start-up probe and the reading cannot drift apart. No behaviour change. Co-Authored-By: Claude Opus 5.5 --- goodwe_controller/app/chargers.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/goodwe_controller/app/chargers.py b/goodwe_controller/app/chargers.py index 45cd67c..0973283 100644 --- a/goodwe_controller/app/chargers.py +++ b/goodwe_controller/app/chargers.py @@ -87,7 +87,9 @@ REQUIRED = ("current", "readback", "state", "power") _SETPOINT_RE = re.compile(r"^number\.(?P.+)_" + SETPOINT_SUFFIX + "$") _ROLE_ORDER = tuple(ROLES) -POWER_UNITS = ("mW", "W", "kW", "MW") # every HA power unit, converted +#: power unit -> W. The probe and the reading both use this one table. +_W_PER = {"mW": 0.001, "W": 1.0, "kW": 1000.0, "MW": 1000000.0} +POWER_UNITS = tuple(_W_PER) def census_key(entity) -> str: @@ -155,9 +157,6 @@ def _amps(obj): return None -_W_PER = {"mW": 0.001, "W": 1.0, "kW": 1000.0, "MW": 1000000.0} - - def _watts(obj): """Power in W, believed only in a power unit (its own copy of the rule: the PV channel's reader stays out of the charger's, test_pv.py part 6)."""