fix(battery): preserve energy below minimum state of charge (#1483)

This commit is contained in:
Andreas
2026-11-01 15:46:45 +01:00
committed by GitHub
parent 33fc5ed61a
commit 298d46a527
6 changed files with 107 additions and 0 deletions
@@ -366,6 +366,9 @@ class Battery:
# Raw extractable energy above minimum SoC
raw_available_wh = max(self.soc_wh - self.min_soc_wh, 0.0)
if raw_available_wh == 0.0:
# A measured SoC below the reserve must not be raised by discharging.
return 0.0, 0.0
# Maximum raw discharge due to power limit, scaled to the slot duration.
# max_charge_power_w is a power [W]; energy movable in one slot is
@@ -304,6 +304,9 @@ class Inverter:
discharged_raw_wh = battery._discharged_raw_wh_per_slot
discharging_efficiency = battery.discharging_efficiency
raw_available_wh = max(soc_wh - min_soc_wh, 0.0)
if raw_available_wh == 0.0:
# Match Battery.discharge_energy(): preserve a SoC below the reserve.
return 0.0, 0.0
max_raw_wh = max(
battery.max_charge_power_w * battery.slot_duration_h - discharged_raw_wh[hour], 0.0
)
@@ -227,6 +227,9 @@ class Genetic0Battery:
# Raw extractable energy above minimum SoC
raw_available_wh = max(self.soc_wh - self.min_soc_wh, 0.0)
if raw_available_wh == 0.0:
# A measured SoC below the reserve must not be raised by discharging.
return 0.0, 0.0
# Maximum raw discharge due to power limit
max_raw_wh = self.max_charge_power_w # TODO rename to max_discharge_power_w