Skip to content

Commit 6e1bbcc

Browse files
committed
added function to check for charging state of system
1 parent cb89cc2 commit 6e1bbcc

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

tests/test_wallbox_proxy.py

+21
Original file line numberDiff line numberDiff line change
@@ -361,3 +361,24 @@ def test_is_pv_charge_activation_allowed(setup_wallboxes_off_state, setup_config
361361
assert wbprox.is_pv_charge_activation_allowed(wallbox[0]) == wb1_result
362362
assert wbprox.is_pv_charge_activation_allowed(wallbox[1]) == wb2_result
363363

364+
365+
@pytest.mark.activate
366+
@pytest.mark.parametrize(
367+
"pv_charge_on, grid_charge_on, result",
368+
[
369+
(True, False, True)
370+
, (True, True, True)
371+
, (False, True, True)
372+
, (False, False, False)
373+
])
374+
def test_is_charging_active(setup_wallboxes_off_state, setup_config, pv_charge_on, grid_charge_on, result):
375+
376+
wallbox = setup_wallboxes_off_state
377+
wbprox = WallboxProxy(setup_config)
378+
379+
wallbox[0].pv_charge_active = pv_charge_on
380+
wallbox[0].grid_charge_active = grid_charge_on
381+
wallbox[1].pv_charge_active = pv_charge_on
382+
wallbox[1].grid_charge_active = grid_charge_on
383+
384+
assert wbprox.is_charging_active(wallbox) == result

wallbox_proxy.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ def activate_pv_charge(self, wallbox_connection: ModbusRTUHeidelbergWB, wallbox:
9999
else: # we do not have enough power. Check if we can deactivate this WB
100100
if self.is_pv_charge_deactivation_allowed(wb):
101101
used_current = 0
102-
# not 0 but stay below min to keep car charge ready (not accounted to current budget)
103-
self.set_current_for_wallbox(wallbox_connection, wb, self.cfg.WB_MIN_CURRENT-1)
102+
self.set_current_for_wallbox(wallbox_connection, wb, used_current)
104103
self.deactivate_pv_charge_for_wallbox(wb)
105104
logging.warning('Charge deactivation for Wallbox ID %s', wb.slave_id)
106105
else: # not allowed, so reduce it to min value for now and try again later
@@ -177,3 +176,9 @@ def deactivate_pv_charge(self, wallbox_connection: ModbusRTUHeidelbergWB, wallbo
177176
wallbox_connection.set_max_current(wb.slave_id, 0)
178177
wb.pv_charge_active = False
179178
wb.last_charge_deactivation = datetime.datetime.now()
179+
180+
def is_charging_active(self, wallbox: List[WBSystemState]) -> bool:
181+
for wb in wallbox:
182+
if wb.pv_charge_active or wb.grid_charge_active:
183+
return True
184+
return False

0 commit comments

Comments
 (0)