From e7ffb38a8e50a11704b0f4a6de06a37dc538f50b Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 6 Apr 2022 19:08:43 -0700 Subject: [PATCH 1/3] fix: add charging_power property --- openevsehttp/__init__.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/openevsehttp/__init__.py b/openevsehttp/__init__.py index 6d454a0..3cecedc 100644 --- a/openevsehttp/__init__.py +++ b/openevsehttp/__init__.py @@ -769,6 +769,17 @@ def wifi_serial(self) -> str | None: return self._config["wifi_serial"] return None + @property + def charging_power(self) -> float: + """Return the charge power. + + Calculate Watts base on V*I + """ + assert self._status is not None + value = round(self._status["voltage"] * (self._status["amp"] / 1000),2) + return value + + # There is currently no min/max amps JSON data # available via HTTP API methods @property From 4b0f6661697eb02dff24d5ce831a68817632202f Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 7 Apr 2022 09:27:58 -0700 Subject: [PATCH 2/3] update tests and linting --- openevsehttp/__init__.py | 3 +-- setup.py | 2 +- tests/fixtures/v4_json/status.json | 2 +- tests/test_init.py | 13 ++++++++++++- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/openevsehttp/__init__.py b/openevsehttp/__init__.py index 3cecedc..83e7a82 100644 --- a/openevsehttp/__init__.py +++ b/openevsehttp/__init__.py @@ -776,10 +776,9 @@ def charging_power(self) -> float: Calculate Watts base on V*I """ assert self._status is not None - value = round(self._status["voltage"] * (self._status["amp"] / 1000),2) + value = round(self._status["voltage"] * self._status["amp"], 2) return value - # There is currently no min/max amps JSON data # available via HTTP API methods @property diff --git a/setup.py b/setup.py index 8357290..060c7f8 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ PROJECT_DIR = Path(__file__).parent.resolve() README_FILE = PROJECT_DIR / "README.md" -VERSION = "0.1.21" +VERSION = "0.1.22" setup( name="python-openevse-http", diff --git a/tests/fixtures/v4_json/status.json b/tests/fixtures/v4_json/status.json index c35bb8b..199fa4f 100644 --- a/tests/fixtures/v4_json/status.json +++ b/tests/fixtures/v4_json/status.json @@ -14,7 +14,7 @@ "comm_success": 332432, "rapi_connected": 1, "evse_connected": 1, - "amp": 0, + "amp": 32.2, "voltage": 240, "pilot": 48, "wh": 64582, diff --git a/tests/test_init.py b/tests/test_init.py index fe092c4..457a591 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -297,7 +297,7 @@ async def test_get_wifi_signal(fixture, expected, request): @pytest.mark.parametrize( - "fixture, expected", [("test_charger", 0), ("test_charger_v2", 0)] + "fixture, expected", [("test_charger", 32.2), ("test_charger_v2", 0)] ) async def test_get_charging_current(fixture, expected, request): """Test v4 Status reply""" @@ -664,3 +664,14 @@ async def test_set_current_v2(test_charger_v2, mock_aioclient, caplog): with caplog.at_level(logging.DEBUG): await test_charger_v2.set_current(12) assert "Setting current via RAPI" in caplog.text + + +@pytest.mark.parametrize( + "fixture, expected", [("test_charger", 7728), ("test_charger_v2", 0)] +) +async def test_get_charging_power(fixture, expected, request): + """Test v4 Status reply""" + charger = request.getfixturevalue(fixture) + await charger.update() + status = charger.charging_power + assert status == expected From b30121ffcb48aee28e4b374a750ffb8cb2280810 Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 7 Apr 2022 09:33:13 -0700 Subject: [PATCH 3/3] bump black version --- requirements_lint.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_lint.txt b/requirements_lint.txt index 3796f96..bc7c7b4 100644 --- a/requirements_lint.txt +++ b/requirements_lint.txt @@ -1,5 +1,5 @@ -r requirements.txt -black==22.1.0 +black==22.3.0 flake8==4.0.1 mypy==0.941 pydocstyle==6.1.1