diff --git a/packages/modules/common/hardware_check.py b/packages/modules/common/hardware_check.py index d8faf3a60e..2dd8931818 100644 --- a/packages/modules/common/hardware_check.py +++ b/packages/modules/common/hardware_check.py @@ -42,8 +42,8 @@ def valid_voltage(voltage) -> bool: (valid_voltage(voltages[0]) and valid_voltage(voltages[1]) and voltages[2] == 0) or (valid_voltage(voltages[0]) and valid_voltage(voltages[1]) and valid_voltage((voltages[2])))): return METER_BROKEN_VOLTAGES.format(voltages) - interdependent_values = [sum(counter_state.currents), counter_state.power] - if not (all(abs(v) < 0.5 for v in interdependent_values) or all(abs(v) > 0.5 for v in interdependent_values)): + if ((sum(counter_state.currents) < 0.5 and counter_state.power > 100) or + (sum(counter_state.currents) > 0.5 and counter_state.power < 100)): return METER_IMPLAUSIBLE_VALUE.format(counter_state.powers, counter_state.currents, counter_state.voltages) return None diff --git a/packages/modules/common/hardware_check_test.py b/packages/modules/common/hardware_check_test.py index 2748001853..9a26b20af5 100644 --- a/packages/modules/common/hardware_check_test.py +++ b/packages/modules/common/hardware_check_test.py @@ -8,8 +8,8 @@ from modules.common.component_state import CounterState, EvseState from modules.common.evse import Evse from modules.common.hardware_check import ( - EVSE_BROKEN, LAN_ADAPTER_BROKEN, METER_BROKEN_VOLTAGES, METER_NO_SERIAL_NUMBER, METER_PROBLEM, - OPEN_TICKET, USB_ADAPTER_BROKEN, SeriesHardwareCheckMixin, _check_meter_values) + EVSE_BROKEN, LAN_ADAPTER_BROKEN, METER_BROKEN_VOLTAGES, METER_IMPLAUSIBLE_VALUE, METER_NO_SERIAL_NUMBER, + METER_PROBLEM, OPEN_TICKET, USB_ADAPTER_BROKEN, SeriesHardwareCheckMixin, _check_meter_values) from modules.common.modbus import NO_CONNECTION, ModbusSerialClient_, ModbusTcpClient_ from modules.conftest import SAMPLE_IP, SAMPLE_PORT from modules.internal_chargepoint_handler.clients import ClientHandler @@ -99,7 +99,7 @@ def test_hardware_check_succeeds(monkeypatch): pytest.param([230]*3, 100, METER_PROBLEM, id="Phantom-Leistung"), ] ) -def test_check_meter_values(voltages, power, expected_msg, monkeypatch): +def test_check_meter_values_voltages(voltages, power, expected_msg, monkeypatch): # setup counter_state = Mock(voltages=voltages, currents=[0, 0, 0], powers=[0, 0, 0], power=power) # execution @@ -109,6 +109,29 @@ def test_check_meter_values(voltages, power, expected_msg, monkeypatch): assert msg == expected_msg if expected_msg is None else expected_msg.format(voltages) +@pytest.mark.parametrize( + "currents, power, expected_msg", + [pytest.param([0.4, 0, 0], -80, None, id="Kriechströme"), + pytest.param([1, 0, 0], 0, METER_IMPLAUSIBLE_VALUE.format([0]*3, [1, 0, 0], [230]*3), + id="zu hoher positiver Strom"), + pytest.param([0, -1, 0], 0, METER_IMPLAUSIBLE_VALUE.format([0]*3, [0, -1, 0], [230]*3), + id="zu hoher negativer Strom"), + pytest.param([0.1, 0, 0], 120, METER_IMPLAUSIBLE_VALUE.format([40]*3, [0.1, 5, 0], [230]*3), + id="zu niedriger Strom bei Leistung"), + ] +) +def test_check_meter_values_powers(currents, power, expected_msg, monkeypatch): + # setup + counter_state = Mock(spec=CounterState, voltages=[230]*3, currents=currents, powers=[power/3]*3, power=power) + # execution + msg = _check_meter_values(counter_state) + + # assert + assert msg == expected_msg if expected_msg is None else expected_msg.format(counter_state.powers, + counter_state.currents, + counter_state.voltages) + + @patch('modules.common.hardware_check.ClientHandlerProtocol') @pytest.mark.parametrize("serial_number, voltages, expected", [("0", [230]*3, (True, METER_NO_SERIAL_NUMBER, CounterState)),