diff --git a/openevsehttp/__init__.py b/openevsehttp/__init__.py index 6d454a0..83e7a82 100644 --- a/openevsehttp/__init__.py +++ b/openevsehttp/__init__.py @@ -769,6 +769,16 @@ 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"], 2) + return value + # There is currently no min/max amps JSON data # available via HTTP API methods @property 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 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