Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions packages/control/consumer/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,25 +121,28 @@ def get_parameter(self) -> Tuple[float, float, Optional[str], Optional[Chargemod
submode = Chargemode.STOP
mode = self.data.usage.chargemode
message = None
wait_for_start_defined_chargemode = False
if self.data.usage.chargemode == Chargemode.SCHEDULED_CHARGING:
required_current, tmp_message, submode = self.wait_for_start_handler(self.scheduled_charging)
required_current, tmp_message, submode, wait_for_start_defined_chargemode = self.wait_for_start_handler(
self.scheduled_charging)
message = f"{tmp_message or ''}".strip()
if submode != Chargemode.INSTANT_CHARGING and self.data.usage.time_charging.active:
required_current, tmp_message, submode = self.time_charging()
# Info vom Zielladen erhalten
message = f"{message or ''} {tmp_message or ''}".strip()
if required_current == 0:
if self.data.usage.chargemode == Chargemode.INSTANT_CHARGING:
required_current, tmp_message, submode = self.instant_charging()
elif self.data.usage.chargemode == Chargemode.ECO_CHARGING:
required_current, tmp_message, submode = self.wait_for_start_handler(self.eco_charging)
elif self.data.usage.chargemode == Chargemode.PV_CHARGING:
required_current, tmp_message, submode = self.wait_for_start_handler(self.pv_charging)
else:
tmp_message = None
message = f"{message or ''} {tmp_message or ''}".strip()
if self.data.usage.chargemode == Chargemode.STOP:
required_current, message, submode = self.stop()
if wait_for_start_defined_chargemode is False:
if submode != Chargemode.INSTANT_CHARGING and self.data.usage.time_charging.active:
required_current, tmp_message, submode = self.time_charging()
# Info vom Zielladen erhalten
message = f"{message or ''} {tmp_message or ''}".strip()
if required_current == 0:
if self.data.usage.chargemode == Chargemode.INSTANT_CHARGING:
required_current, tmp_message, submode = self.instant_charging()
elif self.data.usage.chargemode == Chargemode.ECO_CHARGING:
required_current, tmp_message, submode, _ = self.wait_for_start_handler(self.eco_charging)
elif self.data.usage.chargemode == Chargemode.PV_CHARGING:
required_current, tmp_message, submode, _ = self.wait_for_start_handler(self.pv_charging)
else:
tmp_message = None
message = f"{message or ''} {tmp_message or ''}".strip()
if self.data.usage.chargemode == Chargemode.STOP:
required_current, message, submode = self.stop()
return min_current, required_current, message, mode, submode

def _parse_required_current_by_usage(self, required_current: float) -> float:
Expand Down Expand Up @@ -401,7 +404,8 @@ def stop(self) -> Tuple[float, Optional[str], Chargemode]:

def wait_for_start_handler(
self, func: Callable[[], Tuple[float, Optional[str], Chargemode]]
) -> Tuple[float, Optional[str], Chargemode]:
) -> Tuple[float, Optional[str], Chargemode, bool]:
chargemode_defined_by_wait_for_start_handler = False
if self.data.usage.wait_for_start_active:
if self.data.set.wait_for_start_state == WaitForStartStates.WAIT_FOR_DEVICE_START:
# mit Minimalstrom prüfen, damit Standby-Geräte nicht als laufend erkannt werden
Expand All @@ -410,11 +414,13 @@ def wait_for_start_handler(
required_current = 0
message = self.WAIT_FOR_STOPPED_DEVICE
submode = Chargemode.STOP
chargemode_defined_by_wait_for_start_handler = True
else:
required_current = self._parse_required_current_by_usage(
self._convert_power_to_current(self.data.config.max_power))
message = self.WAIT_FOR_DEVICE_START
submode = Chargemode.INSTANT_CHARGING
chargemode_defined_by_wait_for_start_handler = True
elif self.data.set.wait_for_start_state == WaitForStartStates.WAIT_FOR_STOPPED_DEVICE:
# mit Minimalstrom prüfen, damit Standby-Geräte nicht als laufend erkannt werden
if max(self.data.get.currents) < self.data.config.min_current:
Expand All @@ -426,6 +432,7 @@ def wait_for_start_handler(
required_current = 0
message = self.WAIT_FOR_STOPPED_DEVICE
submode = Chargemode.STOP
chargemode_defined_by_wait_for_start_handler = True
elif self.data.set.wait_for_start_state == WaitForStartStates.DEVICE_WAITING_FOR_START:
# mit Minimalstrom prüfen, damit Standby-Geräte nicht als laufend erkannt werden
if max(self.data.get.currents) > self.data.config.min_current:
Expand All @@ -441,7 +448,7 @@ def wait_for_start_handler(
f"Ungültiger wait_for_start_state {self.data.set.wait_for_start_state} für Verbraucher {self.num}")
else:
required_current, message, submode = func()
return required_current, message, submode
return required_current, message, submode, chargemode_defined_by_wait_for_start_handler

def reset_wait_for_start(self):
self.data.set.wait_for_start_state = WaitForStartStates.WAIT_FOR_DEVICE_START
Expand Down
14 changes: 7 additions & 7 deletions packages/control/consumer/consumer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_get_parameter_clears_previous_state_string_when_switch_interval_is_acti
WaitForStartStates.WAIT_FOR_DEVICE_START,
[0]*3,
(11, "ok", Chargemode.PV_CHARGING),
(11, "ok", Chargemode.PV_CHARGING),
(11, "ok", Chargemode.PV_CHARGING, False),
WaitForStartStates.WAIT_FOR_DEVICE_START,
1,
id="wait-for-start-disabled-passthrough",
Expand All @@ -71,7 +71,7 @@ def test_get_parameter_clears_previous_state_string_when_switch_interval_is_acti
WaitForStartStates.WAIT_FOR_DEVICE_START,
[10]*3,
(9, "running", Chargemode.PV_CHARGING),
(0, Consumer.WAIT_FOR_STOPPED_DEVICE, Chargemode.STOP),
(0, Consumer.WAIT_FOR_STOPPED_DEVICE, Chargemode.STOP, True),
WaitForStartStates.WAIT_FOR_STOPPED_DEVICE,
0,
id="wait-for-device-start-charge-detected",
Expand All @@ -81,7 +81,7 @@ def test_get_parameter_clears_previous_state_string_when_switch_interval_is_acti
WaitForStartStates.WAIT_FOR_DEVICE_START,
[0]*3,
(9, "running", Chargemode.PV_CHARGING),
(10, Consumer.WAIT_FOR_DEVICE_START, Chargemode.INSTANT_CHARGING),
(10, Consumer.WAIT_FOR_DEVICE_START, Chargemode.INSTANT_CHARGING, True),
WaitForStartStates.WAIT_FOR_DEVICE_START,
0,
id="wait-for-device-start-no-charge",
Expand All @@ -91,7 +91,7 @@ def test_get_parameter_clears_previous_state_string_when_switch_interval_is_acti
WaitForStartStates.WAIT_FOR_STOPPED_DEVICE,
[0]*3,
(8, "pv ok", Chargemode.PV_CHARGING),
(8, f"{Consumer.DEVICE_WAITING_FOR_START} pv ok", Chargemode.PV_CHARGING),
(8, f"{Consumer.DEVICE_WAITING_FOR_START} pv ok", Chargemode.PV_CHARGING, False),
WaitForStartStates.DEVICE_WAITING_FOR_START,
1,
id="wait-for-stopped-device-started-waiting",
Expand All @@ -101,7 +101,7 @@ def test_get_parameter_clears_previous_state_string_when_switch_interval_is_acti
WaitForStartStates.DEVICE_WAITING_FOR_START,
[10]*3,
(7, "started", Chargemode.INSTANT_CHARGING),
(7, "started", Chargemode.INSTANT_CHARGING),
(7, "started", Chargemode.INSTANT_CHARGING, False),
WaitForStartStates.START_SIGNAL_RECEIVED,
1,
id="device-waiting-start-signal-received",
Expand All @@ -111,7 +111,7 @@ def test_get_parameter_clears_previous_state_string_when_switch_interval_is_acti
WaitForStartStates.START_SIGNAL_RECEIVED,
[10]*3,
(10, "continue", Chargemode.PV_CHARGING),
(10, "continue", Chargemode.PV_CHARGING),
(10, "continue", Chargemode.PV_CHARGING, False),
WaitForStartStates.START_SIGNAL_RECEIVED,
1,
id="start-signal-received-passthrough",
Expand All @@ -124,7 +124,7 @@ def test_wait_for_start_handler(
state: WaitForStartStates,
currents: List[float],
func_result: Tuple[int, str, Optional[Chargemode]],
expected_result: Tuple[int, str, Optional[Chargemode]],
expected_result: Tuple[int, str, Optional[Chargemode], bool],
expected_state: WaitForStartStates,
func_calls: int,
):
Expand Down
6 changes: 3 additions & 3 deletions packages/helpermodules/setdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,11 +781,11 @@ def process_general_topic(self, msg: mqtt.MQTTMessage):
"openWB/set/general/chargemode_config/surplus/vehicle/switch_on_threshold" in msg.topic or
"openWB/set/general/chargemode_config/surplus/vehicle/switch_on_delay" in msg.topic or
"openWB/set/general/chargemode_config/surplus/vehicle/switch_off_delay" in msg.topic or
"openWB/set/general/consumer/config/switch_on_delay" in msg.topic or
"openWB/set/general/consumer/config/switch_off_delay" in msg.topic):
"openWB/set/general/chargemode_config/surplus/consumer/switch_on_delay" in msg.topic or
"openWB/set/general/chargemode_config/surplus/consumer/switch_off_delay" in msg.topic):
self._validate_value(msg, int, [(0, float("inf"))])
elif ("openWB/set/general/chargemode_config/surplus/vehicle/switch_off_threshold" in msg.topic or
"openWB/set/general/consumer/config/switch_off_threshold" in msg.topic):
"openWB/set/general/chargemode_config/surplus/consumer/switch_off_threshold" in msg.topic):
self._validate_value(msg, float)
elif "openWB/set/general/chargemode_config/surplus/vehicle/phase_switch_delay" in msg.topic:
self._validate_value(msg, int, [(5, 180)])
Expand Down