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
39 changes: 38 additions & 1 deletion packages/control/auto_phase_switch_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from threading import Event
from typing import List, Optional
from typing import List, Optional, Tuple
from unittest.mock import Mock
from control.chargepoint.control_parameter import ControlParameter
from control.counter import Counter, CounterData, Set
Expand Down Expand Up @@ -150,3 +150,40 @@ def test_auto_phase_switch(monkeypatch, vehicle: Ev, params: Params):
assert current == params.expected_current
assert message == params.expected_message
assert control_parameter.state == params.expected_state


@pytest.mark.parametrize(
"evse_current, get_currents, all_surplus, expected",
[
pytest.param(8, [7.7]*3, 100, (False, Ev.ENOUGH_POWER), id="kein 1p3p, genug Leistung für mehrphasige Ladung"),
pytest.param(10, [9.8, 0, 0], 50, (False, Ev.NOT_ENOUGH_POWER),
id="kein 1p3p, nicht genug Leistung, um auf 3p zu schalten"),
pytest.param(16, [14, 0, 0], 5000, (False, Ev.CURRENT_OUT_OF_NOMINAL_DIFFERENCE),
id="kein 1p3p, Auto lädt nicht mit vorgegebener Maximalstromstärke"),
pytest.param(6, [7.5]*3, -20, (False, Ev.CURRENT_OUT_OF_NOMINAL_DIFFERENCE),
id="kein 1p3p, Auto lädt nicht mit vorgegebener Minimalstromstärke"),
pytest.param(16, [15.8, 0, 0], 5000, (True, None), id="1p3p"),
pytest.param(6, [5.8]*3, -10, (True, None), id="3p1p"),
])
def test_check_phase_switch_conditions(evse_current: int,
get_currents: List[float],
all_surplus: int,
expected: Tuple[bool, Optional[str]],
monkeypatch):
# setup
ev = Ev(0)
mock_get_evu_counter = Mock(return_value=Mock(get_usable_surplus=Mock(return_value=all_surplus)))
monkeypatch.setattr(data.data.counter_all_data, "get_evu_counter", mock_get_evu_counter)

# execution
phase_switch, condition_msg = ev._check_phase_switch_conditions(
ChargeTemplate(),
ControlParameter(phases=3-get_currents.count(0)),
evse_current,
get_currents,
sum(get_currents)*230,
16,
LoadmanagementLimit(None, None))

# evaluation
assert (phase_switch, condition_msg) == expected
2 changes: 1 addition & 1 deletion packages/control/chargepoint/chargepoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def initiate_control_pilot_interruption(self):
name=f"cp{self.chargepoint_module.config.id}")):
message = "Control-Pilot-Unterbrechung für " + str(
charging_ev.ev_template.data.control_pilot_interruption_duration) + "s."
self.set_state_and_log(message)
self.set_state_and_log(message)
else:
message = "CP-Unterbrechung nicht möglich, da der Ladepunkt keine CP-Unterbrechung unterstützt."
self.set_state_and_log(message)
Expand Down
9 changes: 7 additions & 2 deletions packages/control/ev/ev.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,15 @@ def _check_phase_switch_conditions(self,
if phases_in_use > 1 and all_surplus > 0:
# genug Leistung, um weiter mehrphasig zu laden
return False, self.ENOUGH_POWER
elif phases_in_use == 1 and all_surplus < required_surplus:
elif phases_in_use == 1 and (all_surplus < required_surplus or unbalanced_load_limit_reached):
# nicht genug Leistung, um mehrphasig zu laden, also einphasig laden
return False, self.NOT_ENOUGH_POWER
elif min_current == evse_current or max_current == evse_current:
elif ((get_medium_charging_current(get_currents) < max_current_range and
evse_current > max_current_range and
phases_in_use == 1) or
(get_medium_charging_current(get_currents) > min_current_range and
evse_current < min_current_range and
phases_in_use > 1)):
# EV lädt nicht mit dem vorgegebenen Strom +/- der erlaubten Abweichung
return False, self.CURRENT_OUT_OF_NOMINAL_DIFFERENCE
else:
Expand Down