Skip to content

Commit ff20159

Browse files
authored
Fix zero currents / zero power (#2705)
* Fix for zero currents and zero power * flake8 * Own function check_currents_power_sign
1 parent a96a29b commit ff20159

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

packages/modules/common/component_state.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ def _calculate_powers_and_currents(currents: Optional[List[Optional[float]]],
4848
return currents, powers, voltages
4949

5050

51+
def check_currents_power_sign(currents: Optional[List[Optional[float]]], power: float) -> bool:
52+
"""Check if the sign of the sum of currents matches the power sign or both zero."""
53+
return any([
54+
sum(currents) < 0 and power < 0,
55+
sum(currents) > 0 and power > 0,
56+
sum(currents) == 0 and power == 0
57+
])
58+
59+
5160
@auto_str
5261
class BatState:
5362
def __init__(
@@ -71,7 +80,7 @@ def __init__(
7180
if _check_none(currents):
7281
currents = [0.0]*3
7382
else:
74-
if not ((sum(currents) < 0 and power < 0) or (sum(currents) > 0 and power > 0)):
83+
if not check_currents_power_sign(currents, power):
7584
log.debug("currents sign wrong "+str(currents))
7685
self.currents = currents
7786

@@ -131,7 +140,7 @@ def __init__(
131140
if _check_none(currents):
132141
currents = [0.0]*3
133142
else:
134-
if not ((sum(currents) < 0 and power < 0) or (sum(currents) > 0 and power > 0)):
143+
if not check_currents_power_sign(currents, power):
135144
log.debug("currents sign wrong "+str(currents))
136145
self.currents = currents
137146
self.power = power

0 commit comments

Comments
 (0)