Skip to content

Commit ab61945

Browse files
committed
Cap StateOfCharge at 0 %
1 parent 4f2fc4b commit ab61945

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

source/energy_classes.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,13 @@ def __repr__(self):
9595
return f"{self.in_percentage} % ({self.absolute})"
9696

9797
def __post_init__(self):
98-
if not self.absolute.watt_hours > battery_capacity.watt_hours:
99-
return
98+
if self.absolute.watt_hours > battery_capacity.watt_hours:
99+
soc_logger.log.debug(f"Capping the state of charge at the battery capacity (would be {self.absolute})")
100+
self.absolute = EnergyAmount(battery_capacity.watt_hours)
100101

101-
soc_logger.log.debug(f"Capping the state of charge at the battery capacity (would be {self.absolute})")
102-
self.absolute = EnergyAmount(battery_capacity.watt_hours)
102+
if self.absolute.watt_hours < 0:
103+
soc_logger.log.debug(f"Capping the state of charge at 0 (would be {self.absolute})")
104+
self.absolute = EnergyAmount(0)
103105

104106
def __add__(self, other: StateOfCharge) -> StateOfCharge:
105107
return StateOfCharge(self.absolute + other.absolute)

0 commit comments

Comments
 (0)