|
1 | 1 | from dataclasses import dataclass |
2 | | -from typing import List |
| 2 | +from typing import List, Optional |
3 | 3 | from unittest.mock import Mock |
4 | 4 | import pytest |
5 | 5 |
|
6 | 6 | from control import data |
| 7 | +from control.chargelog import chargelog |
7 | 8 | from control.chargepoint.chargepoint import Chargepoint |
8 | 9 | from control.chargepoint.chargepoint_state import ChargepointState |
9 | 10 | from control.chargepoint.chargepoint_template import CpTemplate |
| 11 | +from control.counter import Counter |
10 | 12 | from control.ev.ev import Ev |
| 13 | +from modules.common.configurable_vehicle import ConfigurableVehicle |
| 14 | +from modules.vehicles.manual.config import ManualSoc |
| 15 | +from modules.vehicles.manual.soc import create_vehicle as create_manual_vehicle |
| 16 | +from modules.vehicles.tesla.config import TeslaSoc |
| 17 | +from modules.vehicles.tesla.soc import create_vehicle as create_tesla_vehicle |
| 18 | + |
| 19 | + |
| 20 | +@pytest.fixture() |
| 21 | +def mock_data() -> None: |
| 22 | + data.data_init(Mock()) |
11 | 23 |
|
12 | 24 |
|
13 | 25 | @pytest.mark.parametrize("phase_1, phases, expected_required_currents", |
@@ -144,3 +156,43 @@ def test_is_phase_switch_required(params: Params): |
144 | 156 |
|
145 | 157 | # assertion |
146 | 158 | assert ret == params.phase_switch_required |
| 159 | + |
| 160 | + |
| 161 | +@pytest.mark.parametrize( |
| 162 | + "soc_module, reset_after_unplug, expected_calls, expected_pub_call", |
| 163 | + [ |
| 164 | + pytest.param(None, None, 0, None, id="kein SoC-Modul"), |
| 165 | + pytest.param(create_manual_vehicle(ManualSoc(), 0), True, 1, |
| 166 | + ("openWB/set/vehicle/0/soc_module/calculated_soc_state/manual_soc", 0), |
| 167 | + id="manuelles SoC-Modul, Reset nach Abstecken"), |
| 168 | + pytest.param(create_manual_vehicle(ManualSoc(), 0), False, 0, None, |
| 169 | + id="manuelles SoC-Modul, kein Reset nach Abstecken"), |
| 170 | + pytest.param(create_tesla_vehicle(TeslaSoc(), 0), None, 0, None, id="Tesla SoC-Modul"), |
| 171 | + ]) |
| 172 | +def test_process_charge_stop_reset_manual_soc(soc_module: Optional[ConfigurableVehicle], |
| 173 | + reset_after_unplug: Optional[bool], |
| 174 | + expected_calls: int, |
| 175 | + expected_pub_call: Optional[tuple], |
| 176 | + mock_pub: Mock, mock_data, monkeypatch): |
| 177 | + # setup |
| 178 | + cp = Chargepoint(0, None) |
| 179 | + cp.template = CpTemplate() |
| 180 | + cp.data.config.ev = 0 |
| 181 | + cp.data.set.plug_state_prev = True |
| 182 | + ev = Ev(0) |
| 183 | + ev.soc_module = soc_module |
| 184 | + if soc_module and soc_module.vehicle_config.type == "manual": |
| 185 | + ev.soc_module.vehicle_config.configuration.reset_after_unplug = reset_after_unplug |
| 186 | + cp.data.set.charging_ev_data = ev |
| 187 | + data.data.ev_data["ev0"] = ev |
| 188 | + monkeypatch.setattr(chargelog, "save_and_reset_data", Mock()) |
| 189 | + monkeypatch.setattr(data.data.counter_all_data, "get_evu_counter", Mock( |
| 190 | + return_value=Mock(spec=Counter, reset_switch_on_off=Mock()))) |
| 191 | + |
| 192 | + # execution |
| 193 | + cp._process_charge_stop() |
| 194 | + |
| 195 | + # evaluation |
| 196 | + assert len(mock_pub.method_calls) - 1 == expected_calls |
| 197 | + if expected_calls > 0: |
| 198 | + assert mock_pub.method_calls[1].args == expected_pub_call |
0 commit comments