|
1 | 1 | import pytest |
2 | 2 | from threading import Event |
3 | | -from typing import List, Optional |
| 3 | +from typing import List, Optional, Tuple |
4 | 4 | from unittest.mock import Mock |
5 | 5 | from control.chargepoint.control_parameter import ControlParameter |
6 | 6 | from control.counter import Counter, CounterData, Set |
@@ -150,3 +150,40 @@ def test_auto_phase_switch(monkeypatch, vehicle: Ev, params: Params): |
150 | 150 | assert current == params.expected_current |
151 | 151 | assert message == params.expected_message |
152 | 152 | assert control_parameter.state == params.expected_state |
| 153 | + |
| 154 | + |
| 155 | +@pytest.mark.parametrize( |
| 156 | + "evse_current, get_currents, all_surplus, expected", |
| 157 | + [ |
| 158 | + pytest.param(8, [7.7]*3, 100, (False, Ev.ENOUGH_POWER), id="kein 1p3p, genug Leistung für mehrphasige Ladung"), |
| 159 | + pytest.param(10, [9.8, 0, 0], 50, (False, Ev.NOT_ENOUGH_POWER), |
| 160 | + id="kein 1p3p, nicht genug Leistung, um auf 3p zu schalten"), |
| 161 | + pytest.param(16, [14, 0, 0], 5000, (False, Ev.CURRENT_OUT_OF_NOMINAL_DIFFERENCE), |
| 162 | + id="kein 1p3p, Auto lädt nicht mit vorgegebener Maximalstromstärke"), |
| 163 | + pytest.param(6, [7.5]*3, -20, (False, Ev.CURRENT_OUT_OF_NOMINAL_DIFFERENCE), |
| 164 | + id="kein 1p3p, Auto lädt nicht mit vorgegebener Minimalstromstärke"), |
| 165 | + pytest.param(16, [15.8, 0, 0], 5000, (True, None), id="1p3p"), |
| 166 | + pytest.param(6, [5.8]*3, -10, (True, None), id="3p1p"), |
| 167 | + ]) |
| 168 | +def test_check_phase_switch_conditions(evse_current: int, |
| 169 | + get_currents: List[float], |
| 170 | + all_surplus: int, |
| 171 | + expected: Tuple[bool, Optional[str]], |
| 172 | + monkeypatch): |
| 173 | + # setup |
| 174 | + ev = Ev(0) |
| 175 | + mock_get_evu_counter = Mock(return_value=Mock(get_usable_surplus=Mock(return_value=all_surplus))) |
| 176 | + monkeypatch.setattr(data.data.counter_all_data, "get_evu_counter", mock_get_evu_counter) |
| 177 | + |
| 178 | + # execution |
| 179 | + phase_switch, condition_msg = ev._check_phase_switch_conditions( |
| 180 | + ChargeTemplate(), |
| 181 | + ControlParameter(phases=3-get_currents.count(0)), |
| 182 | + evse_current, |
| 183 | + get_currents, |
| 184 | + sum(get_currents)*230, |
| 185 | + 16, |
| 186 | + LoadmanagementLimit(None, None)) |
| 187 | + |
| 188 | + # evaluation |
| 189 | + assert (phase_switch, condition_msg) == expected |
0 commit comments