Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duo+RFID: fix matching if other cp is plugged #1401

Merged
merged 1 commit into from
Feb 2, 2024
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
43 changes: 1 addition & 42 deletions packages/control/chargepoint/chargepoint_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import List, Optional
from typing import List
from unittest.mock import Mock
import pytest
from control import data

from control.chargepoint.chargepoint import Chargepoint
from control.chargepoint.chargepoint_template import CpTemplate
Expand Down Expand Up @@ -50,43 +49,3 @@ def test_check_min_max_current(required_current, phases, expected_required_curre

# assertion
assert ret == expected_required_current


@pytest.fixture()
def mock_data() -> None:
data.data_init(Mock())
data.data.cp_data["cp1"] = Chargepoint(1, None)
data.data.cp_data["cp1"].data.get.rfid = "1234"


@pytest.mark.parametrize("partner_id, cp1_plug_state, cp0_plug_time, cp1_plug_time, expected_set_rfid",
[
pytest.param(None, False, None, None, "1234", id="no duo"),
pytest.param(1, False, None, None, "1234", id="second cp not plugged"),
pytest.param(1, True, "08/08/2023, 11:36:00",
"08/08/2023, 11:37:00", None, id="self first plugged"),
pytest.param(1, True, "08/08/2023, 11:37:00",
"08/08/2023, 11:36:00", "1234", id="second first plugged"),
])
def test_link_rfid_to_cp(partner_id: Optional[int],
cp1_plug_state: bool,
cp0_plug_time: Optional[str],
cp1_plug_time: Optional[str],
expected_set_rfid: Optional[str],
mock_data,
monkeypatch):
# setup
cp = Chargepoint(0, None)
cp.chargepoint_module = Mock()
cp.data.get.rfid = "1234"
cp.data.set.plug_time = cp0_plug_time
data.data.cp_data["cp1"].data.get.plug_state = cp1_plug_state
data.data.cp_data["cp1"].data.set.plug_time = cp1_plug_time
mock_find_duo_partner = Mock(return_value=partner_id)
monkeypatch.setattr(Chargepoint, "find_duo_partner", mock_find_duo_partner)

# execution
cp._link_rfid_to_cp()

# evaluation
assert cp.data.set.rfid == expected_set_rfid
49 changes: 49 additions & 0 deletions packages/control/chargepoint/rfd_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from typing import Optional
from unittest.mock import Mock

import pytest
from control import data
from control.chargepoint.chargepoint import Chargepoint


@pytest.fixture()
def mock_data() -> None:
data.data_init(Mock())
data.data.cp_data["cp1"] = Chargepoint(1, None)
data.data.cp_data["cp1"].data.get.rfid = "1234"


@pytest.mark.parametrize(
"partner_id, cp0_plug_state, cp1_plug_state, cp0_plug_time, cp1_plug_time, expected_set_rfid",
[
pytest.param(None, True, False, None, None, "1234", id="no duo"),
pytest.param(1, True, False, None, None, "1234", id="second cp not plugged"),
pytest.param(1, True, True, 1706868636, 1706868646, None, id="self first plugged"),
pytest.param(1, True, True, 1706868636, 1706868626, "1234", id="second first plugged"),
pytest.param(1, False, True, None, 1706868626, None,
id="second plugged, self not plugged yet, wait for plugging"),
])
def test_link_rfid_to_cp(partner_id: Optional[int],
cp0_plug_state: bool,
cp1_plug_state: bool,
cp0_plug_time: Optional[str],
cp1_plug_time: Optional[str],
expected_set_rfid: Optional[str],
mock_data,
monkeypatch):
# setup
cp = Chargepoint(0, None)
cp.chargepoint_module = Mock()
cp.data.get.rfid = "1234"
cp.data.get.plug_state = cp0_plug_state
cp.data.set.plug_time = cp0_plug_time
data.data.cp_data["cp1"].data.get.plug_state = cp1_plug_state
data.data.cp_data["cp1"].data.set.plug_time = cp1_plug_time
mock_find_duo_partner = Mock(return_value=partner_id)
monkeypatch.setattr(Chargepoint, "find_duo_partner", mock_find_duo_partner)

# execution
cp._link_rfid_to_cp()

# evaluation
assert cp.data.set.rfid == expected_set_rfid
15 changes: 8 additions & 7 deletions packages/control/chargepoint/rfid.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,22 @@

class ChargepointRfidMixin:
def _link_rfid_to_cp(self: ChargepointProtocol) -> None:
""" Wenn der Tag einem EV zugeordnet worden ist, wird der Tag unter set/rfid abgelegt und muss der Timer
""" tested
Wenn der Tag einem EV zugeordnet worden ist, wird der Tag unter set/rfid abgelegt und muss der Timer
zurückgesetzt werden.
"""
rfid = self.data.get.rfid
cp2_num = self.find_duo_partner()
cp2_data = data.data.cp_data[f"cp{cp2_num}"] if cp2_num is not None else None
# Tag wird diesem LP der Duo zugewiesen oder es ist keine Duo
if ((cp2_num is not None and
if ((cp2_data is not None and
# EV am anderen Ladepunkt, am eigenen wurde zuerst angesteckt
((data.data.cp_data[f"cp{cp2_num}"].data.get.plug_state and
timecheck.get_difference(self.data.set.plug_time,
data.data.cp_data[f"cp{cp2_num}"].data.set.plug_time) < 0) or
((cp2_data.data.get.plug_state and self.data.get.plug_state and
(cp2_data.data.set.plug_time - self.data.set.plug_time) < 0) or
# kein EV am anderen Duo-Ladepunkt
data.data.cp_data[f"cp{cp2_num }"].data.get.plug_state is False)) or
cp2_data.data.get.plug_state is False)) or
# keine Duo
cp2_num is None):
cp2_data is None):
self.data.set.rfid = rfid
Pub().pub("openWB/chargepoint/"+str(self.num)+"/set/rfid", rfid)
self.chargepoint_module.clear_rfid()
Expand Down
Loading