From 0a1e3e778722b3dab72322beae3891406c18fab1 Mon Sep 17 00:00:00 2001 From: SeaSpotter Date: Wed, 27 Aug 2025 20:19:36 +0200 Subject: [PATCH 1/3] Fix for zero currents and zero power --- packages/modules/common/component_state.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/modules/common/component_state.py b/packages/modules/common/component_state.py index ee856d4e22..bf1a9459d5 100644 --- a/packages/modules/common/component_state.py +++ b/packages/modules/common/component_state.py @@ -71,7 +71,11 @@ def __init__( if _check_none(currents): currents = [0.0]*3 else: - if not ((sum(currents) < 0 and power < 0) or (sum(currents) > 0 and power > 0)): + if not ( + (sum(currents) < 0 and power < 0) or + (sum(currents) > 0 and power > 0) or + (sum(currents) == 0 and power == 0) + ): log.debug("currents sign wrong "+str(currents)) self.currents = currents @@ -131,7 +135,11 @@ def __init__( if _check_none(currents): currents = [0.0]*3 else: - if not ((sum(currents) < 0 and power < 0) or (sum(currents) > 0 and power > 0)): + if not ( + (sum(currents) < 0 and power < 0) or + (sum(currents) > 0 and power > 0) or + (sum(currents) == 0 and power == 0) + ): log.debug("currents sign wrong "+str(currents)) self.currents = currents self.power = power From 3f635ec9bdf26ead32cf5e1b0b567bd512c96d41 Mon Sep 17 00:00:00 2001 From: SeaSpotter Date: Wed, 27 Aug 2025 20:27:59 +0200 Subject: [PATCH 2/3] flake8 --- packages/modules/common/component_state.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/modules/common/component_state.py b/packages/modules/common/component_state.py index bf1a9459d5..11fad61e92 100644 --- a/packages/modules/common/component_state.py +++ b/packages/modules/common/component_state.py @@ -72,8 +72,8 @@ def __init__( currents = [0.0]*3 else: if not ( - (sum(currents) < 0 and power < 0) or - (sum(currents) > 0 and power > 0) or + (sum(currents) < 0 and power < 0) or + (sum(currents) > 0 and power > 0) or (sum(currents) == 0 and power == 0) ): log.debug("currents sign wrong "+str(currents)) @@ -136,8 +136,8 @@ def __init__( currents = [0.0]*3 else: if not ( - (sum(currents) < 0 and power < 0) or - (sum(currents) > 0 and power > 0) or + (sum(currents) < 0 and power < 0) or + (sum(currents) > 0 and power > 0) or (sum(currents) == 0 and power == 0) ): log.debug("currents sign wrong "+str(currents)) From 804f1f9da9ef087581e311df43cd15d18cc800eb Mon Sep 17 00:00:00 2001 From: SeaSpotter Date: Fri, 29 Aug 2025 09:10:07 +0200 Subject: [PATCH 3/3] Own function check_currents_power_sign --- packages/modules/common/component_state.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/modules/common/component_state.py b/packages/modules/common/component_state.py index 11fad61e92..7eb3ff5990 100644 --- a/packages/modules/common/component_state.py +++ b/packages/modules/common/component_state.py @@ -48,6 +48,15 @@ def _calculate_powers_and_currents(currents: Optional[List[Optional[float]]], return currents, powers, voltages +def check_currents_power_sign(currents: Optional[List[Optional[float]]], power: float) -> bool: + """Check if the sign of the sum of currents matches the power sign or both zero.""" + return any([ + sum(currents) < 0 and power < 0, + sum(currents) > 0 and power > 0, + sum(currents) == 0 and power == 0 + ]) + + @auto_str class BatState: def __init__( @@ -71,11 +80,7 @@ def __init__( if _check_none(currents): currents = [0.0]*3 else: - if not ( - (sum(currents) < 0 and power < 0) or - (sum(currents) > 0 and power > 0) or - (sum(currents) == 0 and power == 0) - ): + if not check_currents_power_sign(currents, power): log.debug("currents sign wrong "+str(currents)) self.currents = currents @@ -135,11 +140,7 @@ def __init__( if _check_none(currents): currents = [0.0]*3 else: - if not ( - (sum(currents) < 0 and power < 0) or - (sum(currents) > 0 and power > 0) or - (sum(currents) == 0 and power == 0) - ): + if not check_currents_power_sign(currents, power): log.debug("currents sign wrong "+str(currents)) self.currents = currents self.power = power