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

Extend measurement values for pro #1130

Merged
merged 2 commits into from
Oct 16, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def get_values(self) -> None:

chargepoint_state = ChargepointState(
power=json_rsp["power_all"],
powers=json_rsp["powers"],
currents=json_rsp["currents"],
imported=json_rsp["imported"],
exported=json_rsp["exported"],
Expand All @@ -57,6 +58,12 @@ def get_values(self) -> None:
rfid=json_rsp["vehicle_id"]
)

if json_rsp.get("voltages") is not None:
chargepoint_state.voltages = json_rsp["voltages"]

if json_rsp.get("frequency") is not None:
chargepoint_state.frequency = json_rsp["frequency"]

self.store.set(chargepoint_state)
self.__client_error_context.reset_error_counter()

Expand Down
81 changes: 61 additions & 20 deletions packages/modules/chargepoints/openwb_pro/chargepoint_module_test.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,18 @@
from typing import Dict
from unittest.mock import Mock

import requests_mock
from modules.chargepoints.openwb_pro.config import OpenWBPro, OpenWBProConfiguration

import pytest

from modules.chargepoints.openwb_pro.config import OpenWBPro, OpenWBProConfiguration
from modules.common.component_state import ChargepointState
from modules.chargepoints.openwb_pro import chargepoint_module

SAMPLE_IP = "1.1.1.1"


def test_openwb_pro(monkeypatch, requests_mock: requests_mock.mock):
# setup
mock_chargepoint_value_store = Mock()
monkeypatch.setattr(chargepoint_module, 'get_chargepoint_value_store',
Mock(return_value=mock_chargepoint_value_store))
requests_mock.post(f'http://{SAMPLE_IP}/connect.php')
requests_mock.get(f'http://{SAMPLE_IP}/connect.php', json=SAMPLE)

cp = chargepoint_module.ChargepointModule(OpenWBPro(configuration=OpenWBProConfiguration(ip_address=SAMPLE_IP)))

# execution
cp.get_values()

# evaluation
assert vars(mock_chargepoint_value_store.set.call_args[0][0]) == vars(SAMPLE_CHARGEPOINT_STATE)


SAMPLE_CHARGEPOINT_STATE = ChargepointState(
power=4302.7,
powers=[1444.4, 1423.7, 1438.1],
currents=[6.133, 6.066, 6.122],
imported=10839,
exported=0,
Expand All @@ -55,3 +39,60 @@ def test_openwb_pro(monkeypatch, requests_mock: requests_mock.mock):
'timestamp': 1675104511,
'v2g_ready': 0,
'vehicle_id': '98:ED:5C:B4:EE:8D'}

SAMPLE_CHARGEPOINT_STATE_EXTENDED = ChargepointState(
power=0,
powers=[0]*3,
currents=[0]*3,
voltages=[230.67, 0, 0],
imported=6827330,
exported=0,
plug_state=False,
charge_state=False,
phases_in_use=1,
rfid=None,
frequency=50.2
)

SAMPLE_EXTENDED = {"date": "2023:09:18-15:13:41",
"timestamp": 1695042821,
"powers": [0, 0, 0],
"power_all": 0,
"currents": [0, 0, 0],
"voltages": [230.67, 0, 0],
"imported": 6827330,
"exported": 0,
"plug_state": False,
"charge_state": False,
"phases_actual": 0,
"phases_target": 3,
"phases_in_use": 1,
"offered_current": 6,
"evse_signaling": "unclear\n",
"v2g_ready": 0,
"soc_value": 0,
"soc_timestamp": "0",
"vehicle_id": None,
"serial": "493826",
"frequency": 50.2}


@pytest.mark.parametrize("sample_state, expected_state",
[pytest.param(SAMPLE, SAMPLE_CHARGEPOINT_STATE),
pytest.param(SAMPLE_EXTENDED, SAMPLE_CHARGEPOINT_STATE_EXTENDED)
])
def test_openwb_pro(sample_state: Dict, expected_state: Dict, monkeypatch, requests_mock: requests_mock.mock):
# setup
mock_chargepoint_value_store = Mock()
monkeypatch.setattr(chargepoint_module, 'get_chargepoint_value_store',
Mock(return_value=mock_chargepoint_value_store))
requests_mock.post(f'http://{SAMPLE_IP}/connect.php')
requests_mock.get(f'http://{SAMPLE_IP}/connect.php', json=sample_state)

cp = chargepoint_module.ChargepointModule(OpenWBPro(configuration=OpenWBProConfiguration(ip_address=SAMPLE_IP)))

# execution
cp.get_values()

# evaluation
assert vars(mock_chargepoint_value_store.set.call_args[0][0]) == vars(expected_state)