From 08838bace434f78dd9068850fa3f4983ca23850a Mon Sep 17 00:00:00 2001 From: Alberto Geniola Date: Sat, 23 Nov 2024 22:18:50 +0100 Subject: [PATCH 1/9] Fix wrong mode selection when setting up direct connection to Panel --- homeassistant/components/elmax/config_flow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/elmax/config_flow.py b/homeassistant/components/elmax/config_flow.py index bf479e997efba..3bb01efd3d53b 100644 --- a/homeassistant/components/elmax/config_flow.py +++ b/homeassistant/components/elmax/config_flow.py @@ -203,7 +203,7 @@ async def _test_direct_and_create_entry(self): async def async_step_direct(self, user_input: dict[str, Any]) -> ConfigFlowResult: """Handle the direct setup step.""" - self._selected_mode = CONF_ELMAX_MODE_CLOUD + self._selected_mode = CONF_ELMAX_MODE_DIRECT if user_input is None: return self.async_show_form( step_id=CONF_ELMAX_MODE_DIRECT, From f37eed2e14817f18a83931b86fb9f9d26515c198 Mon Sep 17 00:00:00 2001 From: Alberto Geniola Date: Sat, 23 Nov 2024 22:20:44 +0100 Subject: [PATCH 2/9] Upgrade dependency to elmax-api --- homeassistant/components/elmax/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/elmax/manifest.json b/homeassistant/components/elmax/manifest.json index efa97a9f6b958..f599342a30dab 100644 --- a/homeassistant/components/elmax/manifest.json +++ b/homeassistant/components/elmax/manifest.json @@ -6,7 +6,7 @@ "documentation": "https://www.home-assistant.io/integrations/elmax", "iot_class": "cloud_polling", "loggers": ["elmax_api"], - "requirements": ["elmax-api==0.0.6.1"], + "requirements": ["elmax-api==0.0.6.2"], "zeroconf": [ { "type": "_elmax-ssl._tcp.local." diff --git a/requirements_all.txt b/requirements_all.txt index 4d114841761b3..adab26b00bb39 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -821,7 +821,7 @@ eliqonline==1.2.2 elkm1-lib==2.2.10 # homeassistant.components.elmax -elmax-api==0.0.6.1 +elmax-api==0.0.6.2 # homeassistant.components.elvia elvia==0.1.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 9c0d22b51ec87..6a3e9a2307635 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -696,7 +696,7 @@ elgato==5.1.2 elkm1-lib==2.2.10 # homeassistant.components.elmax -elmax-api==0.0.6.1 +elmax-api==0.0.6.2 # homeassistant.components.elvia elvia==0.1.0 From 5762f40c2209b364968f6a98f114bbcc44041c7d Mon Sep 17 00:00:00 2001 From: Alberto Geniola Date: Sat, 23 Nov 2024 22:29:29 +0100 Subject: [PATCH 3/9] Improve code quality --- homeassistant/components/elmax/common.py | 2 +- homeassistant/components/elmax/cover.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/elmax/common.py b/homeassistant/components/elmax/common.py index 88e61e36a683d..18350e45efeb0 100644 --- a/homeassistant/components/elmax/common.py +++ b/homeassistant/components/elmax/common.py @@ -35,7 +35,7 @@ def check_local_version_supported(api_version: str | None) -> bool: class DirectPanel(PanelEntry): """Helper class for wrapping a directly accessed Elmax Panel.""" - def __init__(self, panel_uri): + def __init__(self, panel_uri) -> None: """Construct the object.""" super().__init__(panel_uri, True, {}) diff --git a/homeassistant/components/elmax/cover.py b/homeassistant/components/elmax/cover.py index a53c28c5f338b..403bc51dbffab 100644 --- a/homeassistant/components/elmax/cover.py +++ b/homeassistant/components/elmax/cover.py @@ -121,13 +121,13 @@ async def async_stop_cover(self, **kwargs: Any) -> None: else: _LOGGER.debug("Ignoring stop request as the cover is IDLE") - async def async_open_cover(self, **kwargs): + async def async_open_cover(self, **kwargs: Any) -> None: """Open the cover.""" await self.coordinator.http_client.execute_command( endpoint_id=self._device.endpoint_id, command=CoverCommand.UP ) - async def async_close_cover(self, **kwargs): + async def async_close_cover(self, **kwargs: Any) -> None: """Close the cover.""" await self.coordinator.http_client.execute_command( endpoint_id=self._device.endpoint_id, command=CoverCommand.DOWN From 0c42ec92f49b7cbfd970f7a36fb6ca63ba46ddce Mon Sep 17 00:00:00 2001 From: Alberto Geniola Date: Thu, 28 Nov 2024 21:06:41 +0100 Subject: [PATCH 4/9] Update elmax library requirement --- homeassistant/components/elmax/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/elmax/manifest.json b/homeassistant/components/elmax/manifest.json index f599342a30dab..19e4209d62c5e 100644 --- a/homeassistant/components/elmax/manifest.json +++ b/homeassistant/components/elmax/manifest.json @@ -6,7 +6,7 @@ "documentation": "https://www.home-assistant.io/integrations/elmax", "iot_class": "cloud_polling", "loggers": ["elmax_api"], - "requirements": ["elmax-api==0.0.6.2"], + "requirements": ["elmax-api==0.0.6.3rc2"], "zeroconf": [ { "type": "_elmax-ssl._tcp.local." diff --git a/requirements_all.txt b/requirements_all.txt index adab26b00bb39..d058c4d9d1baf 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -821,7 +821,7 @@ eliqonline==1.2.2 elkm1-lib==2.2.10 # homeassistant.components.elmax -elmax-api==0.0.6.2 +elmax-api==0.0.6.3rc2 # homeassistant.components.elvia elvia==0.1.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 6a3e9a2307635..72fd933642d5d 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -696,7 +696,7 @@ elgato==5.1.2 elkm1-lib==2.2.10 # homeassistant.components.elmax -elmax-api==0.0.6.2 +elmax-api==0.0.6.3rc2 # homeassistant.components.elvia elvia==0.1.0 From f276f11262a336d170523c7eb9a9e656257d8d7c Mon Sep 17 00:00:00 2001 From: Alberto Geniola Date: Sun, 1 Dec 2024 20:00:42 +0100 Subject: [PATCH 5/9] Reference the latest stable elmax-api library requirement --- homeassistant/components/elmax/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/elmax/manifest.json b/homeassistant/components/elmax/manifest.json index 19e4209d62c5e..dfa20326d0c1f 100644 --- a/homeassistant/components/elmax/manifest.json +++ b/homeassistant/components/elmax/manifest.json @@ -6,7 +6,7 @@ "documentation": "https://www.home-assistant.io/integrations/elmax", "iot_class": "cloud_polling", "loggers": ["elmax_api"], - "requirements": ["elmax-api==0.0.6.3rc2"], + "requirements": ["elmax-api==0.0.6.3"], "zeroconf": [ { "type": "_elmax-ssl._tcp.local." diff --git a/requirements_all.txt b/requirements_all.txt index d058c4d9d1baf..55a5d3a9e5add 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -821,7 +821,7 @@ eliqonline==1.2.2 elkm1-lib==2.2.10 # homeassistant.components.elmax -elmax-api==0.0.6.3rc2 +elmax-api==0.0.6.3 # homeassistant.components.elvia elvia==0.1.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 72fd933642d5d..6c4349415ab78 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -696,7 +696,7 @@ elgato==5.1.2 elkm1-lib==2.2.10 # homeassistant.components.elmax -elmax-api==0.0.6.3rc2 +elmax-api==0.0.6.3 # homeassistant.components.elvia elvia==0.1.0 From 0c75206e4833940f562e6b24790f4385fc4411e0 Mon Sep 17 00:00:00 2001 From: Alberto Geniola Date: Sat, 23 Nov 2024 22:20:44 +0100 Subject: [PATCH 6/9] Upgrade dependency to elmax-api --- homeassistant/components/elmax/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/elmax/manifest.json b/homeassistant/components/elmax/manifest.json index dfa20326d0c1f..efa97a9f6b958 100644 --- a/homeassistant/components/elmax/manifest.json +++ b/homeassistant/components/elmax/manifest.json @@ -6,7 +6,7 @@ "documentation": "https://www.home-assistant.io/integrations/elmax", "iot_class": "cloud_polling", "loggers": ["elmax_api"], - "requirements": ["elmax-api==0.0.6.3"], + "requirements": ["elmax-api==0.0.6.1"], "zeroconf": [ { "type": "_elmax-ssl._tcp.local." From 2f0b000e8ceda1d917944b12081fa42ded4cb1f0 Mon Sep 17 00:00:00 2001 From: Alberto Geniola Date: Thu, 28 Nov 2024 21:06:41 +0100 Subject: [PATCH 7/9] Update elmax library requirement --- homeassistant/components/elmax/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/elmax/manifest.json b/homeassistant/components/elmax/manifest.json index efa97a9f6b958..f599342a30dab 100644 --- a/homeassistant/components/elmax/manifest.json +++ b/homeassistant/components/elmax/manifest.json @@ -6,7 +6,7 @@ "documentation": "https://www.home-assistant.io/integrations/elmax", "iot_class": "cloud_polling", "loggers": ["elmax_api"], - "requirements": ["elmax-api==0.0.6.1"], + "requirements": ["elmax-api==0.0.6.2"], "zeroconf": [ { "type": "_elmax-ssl._tcp.local." From c3055f35060fb7af344d519859dab74854bf9a5f Mon Sep 17 00:00:00 2001 From: Alberto Geniola Date: Sun, 1 Dec 2024 20:00:42 +0100 Subject: [PATCH 8/9] Reference the latest stable elmax-api library requirement --- homeassistant/components/elmax/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/elmax/manifest.json b/homeassistant/components/elmax/manifest.json index f599342a30dab..dfa20326d0c1f 100644 --- a/homeassistant/components/elmax/manifest.json +++ b/homeassistant/components/elmax/manifest.json @@ -6,7 +6,7 @@ "documentation": "https://www.home-assistant.io/integrations/elmax", "iot_class": "cloud_polling", "loggers": ["elmax_api"], - "requirements": ["elmax-api==0.0.6.2"], + "requirements": ["elmax-api==0.0.6.3"], "zeroconf": [ { "type": "_elmax-ssl._tcp.local." From b9f989178b62a4dff201423b306d3ad0eafe648b Mon Sep 17 00:00:00 2001 From: Alberto Geniola Date: Wed, 4 Dec 2024 21:58:01 +0100 Subject: [PATCH 9/9] Fix JWT fixture to adjust expiration. --- tests/components/elmax/conftest.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/components/elmax/conftest.py b/tests/components/elmax/conftest.py index f92fc2f18278c..f8cf33ffe1a09 100644 --- a/tests/components/elmax/conftest.py +++ b/tests/components/elmax/conftest.py @@ -1,6 +1,7 @@ """Configuration for Elmax tests.""" from collections.abc import Generator +from datetime import datetime, timedelta import json from unittest.mock import AsyncMock, patch @@ -11,6 +12,7 @@ ENDPOINT_LOGIN, ) from httpx import Response +import jwt import pytest import respx @@ -64,9 +66,20 @@ def httpx_mock_direct_fixture() -> Generator[respx.MockRouter]: ) as respx_mock: # Mock Login POST. login_route = respx_mock.post(f"/api/v2/{ENDPOINT_LOGIN}", name="login") - login_route.return_value = Response( - 200, json=json.loads(load_fixture("direct/login.json", "elmax")) + + login_json = json.loads(load_fixture("direct/login.json", "elmax")) + decoded_jwt = jwt.decode_complete( + login_json["token"].split(" ")[1], + algorithms="HS256", + options={"verify_signature": False}, + ) + expiration = datetime.now() + timedelta(hours=1) + decoded_jwt["payload"]["exp"] = int(expiration.timestamp()) + jws_string = jwt.encode( + payload=decoded_jwt["payload"], algorithm="HS256", key="" ) + login_json["token"] = f"JWT {jws_string}" + login_route.return_value = Response(200, json=login_json) # Mock Device list GET. list_devices_route = respx_mock.get(