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
4 changes: 2 additions & 2 deletions packages/modules/common/hardware_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 26 additions & 3 deletions packages/modules/common/hardware_check_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)),
Expand Down