From d9ca6967ecd91304f10f1142c0640452b84033eb Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 5 Jun 2024 14:03:52 +0200 Subject: [PATCH 01/12] Define specific timeouts for legacy and actual gateways --- plugwise/constants.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugwise/constants.py b/plugwise/constants.py index 00331b553..677766796 100644 --- a/plugwise/constants.py +++ b/plugwise/constants.py @@ -32,7 +32,8 @@ ADAM: Final = "Adam" ANNA: Final = "Smile Anna" -DEFAULT_TIMEOUT: Final = 30 +DEFAULT_TIMEOUT: Final = 10 +DEFAULT_LEGACY_TIMEOUT: Final = 30 DEFAULT_USERNAME: Final = "smile" DEFAULT_PORT: Final = 80 DEFAULT_PW_MAX: Final = 30.0 From a3ebf6373650cd73f65e52bb80f00a731aad827b Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 5 Jun 2024 14:15:14 +0200 Subject: [PATCH 02/12] Use specific timeout after first connect() --- plugwise/__init__.py | 5 +---- plugwise/legacy/smile.py | 5 +++-- plugwise/smile.py | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 7faef69a6..ffd48a7bd 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -46,7 +46,7 @@ def __init__( websession: aiohttp.ClientSession, username: str = DEFAULT_USERNAME, port: int = DEFAULT_PORT, - timeout: float = DEFAULT_TIMEOUT, + timeout: float = DEFAULT_LEGACY_TIMEOUT, ) -> None: """Set the constructor for this class.""" @@ -64,7 +64,6 @@ def __init__( self._websession = websession self._user = username self._port = port - self._timeout = timeout self._cooling_present = False self._elga = False @@ -147,7 +146,6 @@ async def connect(self) -> bool: self.smile_type, self._user, self._port, - self._timeout, ) if not self.smile_legacy else SmileLegacyAPI( self._host, self._passwd, @@ -168,7 +166,6 @@ async def connect(self) -> bool: self.smile_zigbee_mac_address, self._user, self._port, - self._timeout, ) # Update all endpoints on first connect diff --git a/plugwise/legacy/smile.py b/plugwise/legacy/smile.py index e72621b82..a0db56c8c 100644 --- a/plugwise/legacy/smile.py +++ b/plugwise/legacy/smile.py @@ -10,7 +10,7 @@ from plugwise.constants import ( APPLIANCES, DEFAULT_PORT, - DEFAULT_TIMEOUT, + DEFAULT_LEGACY_TIMEOUT, DEFAULT_USERNAME, DOMAIN_OBJECTS, LOCATIONS, @@ -58,7 +58,7 @@ def __init__( smile_zigbee_mac_address: str | None, username: str = DEFAULT_USERNAME, port: int = DEFAULT_PORT, - timeout: float = DEFAULT_TIMEOUT, + timeout: float = DEFAULT_LEGACY_TIMEOUT, ) -> None: """Set the constructor for this class.""" super().__init__( @@ -77,6 +77,7 @@ def __init__( self._opentherm_device = _opentherm_device self._stretch_v2 = _stretch_v2 self._target_smile = _target_smile + self._timeout = timeout self.loc_data = loc_data self.smile_fw_version = smile_fw_version self.smile_hostname = smile_hostname diff --git a/plugwise/smile.py b/plugwise/smile.py index ef3e13d55..7addc9a7f 100644 --- a/plugwise/smile.py +++ b/plugwise/smile.py @@ -67,7 +67,6 @@ def __init__( username: str = DEFAULT_USERNAME, port: int = DEFAULT_PORT, timeout: float = DEFAULT_TIMEOUT, - ) -> None: """Set the constructor for this class.""" super().__init__( @@ -87,6 +86,7 @@ def __init__( self._on_off_device = _on_off_device self._opentherm_device = _opentherm_device self._schedule_old_states = _schedule_old_states + self._timeout = timeout self.gateway_id = gateway_id self.loc_data = loc_data self.smile_fw_version = smile_fw_version From 2f7f58a31709ffe5020e9444db48179d53acaba8 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 5 Jun 2024 14:18:15 +0200 Subject: [PATCH 03/12] Fix --- plugwise/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index ffd48a7bd..12164e4e9 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -6,7 +6,7 @@ from plugwise.constants import ( DEFAULT_PORT, - DEFAULT_TIMEOUT, + DEFAULT_LEGACY_TIMEOUT, DEFAULT_USERNAME, DOMAIN_OBJECTS, LOGGER, From 5a20adce0402b8ecca590bda625e9d705267143e Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 5 Jun 2024 14:49:09 +0200 Subject: [PATCH 04/12] Sort imports --- plugwise/__init__.py | 2 +- plugwise/legacy/smile.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 12164e4e9..de0755c0c 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -5,8 +5,8 @@ from __future__ import annotations from plugwise.constants import ( - DEFAULT_PORT, DEFAULT_LEGACY_TIMEOUT, + DEFAULT_PORT, DEFAULT_USERNAME, DOMAIN_OBJECTS, LOGGER, diff --git a/plugwise/legacy/smile.py b/plugwise/legacy/smile.py index a0db56c8c..d66a2a5dc 100644 --- a/plugwise/legacy/smile.py +++ b/plugwise/legacy/smile.py @@ -9,8 +9,8 @@ from plugwise.constants import ( APPLIANCES, - DEFAULT_PORT, DEFAULT_LEGACY_TIMEOUT, + DEFAULT_PORT, DEFAULT_USERNAME, DOMAIN_OBJECTS, LOCATIONS, From c376e76800a1720a4fdb055426aa1f357e68620d Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 5 Jun 2024 15:04:41 +0200 Subject: [PATCH 05/12] Add extra smile._timeout asserts --- tests/test_init.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_init.py b/tests/test_init.py index b6c0dc47f..142167ea9 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -552,8 +552,10 @@ async def device_test( await smile.full_update_device() smile.get_all_devices() data = await smile.async_update() + assert smile._timeout == 30 else: data = await smile.async_update() + assert smile._timeout == 10 else: _LOGGER.info("Asserting updated testdata:") data = await smile.async_update() From b1965ddeaf67cbec8a9b4005058dc4c1c79b2e07 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 5 Jun 2024 15:21:52 +0200 Subject: [PATCH 06/12] Update timeout after knowing if legacy or not --- plugwise/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index de0755c0c..61e611e21 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -56,7 +56,7 @@ def __init__( websession, username, port, - timeout, + self._timeout, ) self._host = host @@ -64,6 +64,7 @@ def __init__( self._websession = websession self._user = username self._port = port + self._timeout = timeout self._cooling_present = False self._elga = False @@ -146,6 +147,7 @@ async def connect(self) -> bool: self.smile_type, self._user, self._port, + self._timeout, ) if not self.smile_legacy else SmileLegacyAPI( self._host, self._passwd, @@ -166,6 +168,7 @@ async def connect(self) -> bool: self.smile_zigbee_mac_address, self._user, self._port, + self._timeout, ) # Update all endpoints on first connect @@ -189,6 +192,9 @@ async def _smile_detect(self, result: etree, dsmrmain: etree) -> None: else: model = await self._smile_detect_legacy(result, dsmrmain, model) + if not self.smile_legacy: + self._timeout = DEFAULT_TIMEOUT + if model == "Unknown" or self.smile_fw_version is None: # pragma: no cover # Corner case check LOGGER.error( From e023ce5b0c59094d3497c2c1f0ea0c4705dca424 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 5 Jun 2024 15:23:21 +0200 Subject: [PATCH 07/12] Don't overwrite passed-down timeout value --- plugwise/legacy/smile.py | 3 +-- plugwise/smile.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/plugwise/legacy/smile.py b/plugwise/legacy/smile.py index d66a2a5dc..3369d951e 100644 --- a/plugwise/legacy/smile.py +++ b/plugwise/legacy/smile.py @@ -9,7 +9,6 @@ from plugwise.constants import ( APPLIANCES, - DEFAULT_LEGACY_TIMEOUT, DEFAULT_PORT, DEFAULT_USERNAME, DOMAIN_OBJECTS, @@ -58,7 +57,7 @@ def __init__( smile_zigbee_mac_address: str | None, username: str = DEFAULT_USERNAME, port: int = DEFAULT_PORT, - timeout: float = DEFAULT_LEGACY_TIMEOUT, + timeout: float, ) -> None: """Set the constructor for this class.""" super().__init__( diff --git a/plugwise/smile.py b/plugwise/smile.py index 7addc9a7f..ae612cfeb 100644 --- a/plugwise/smile.py +++ b/plugwise/smile.py @@ -12,7 +12,6 @@ ANNA, APPLIANCES, DEFAULT_PORT, - DEFAULT_TIMEOUT, DEFAULT_USERNAME, DOMAIN_OBJECTS, GATEWAY_REBOOT, @@ -66,7 +65,7 @@ def __init__( smile_type: str, username: str = DEFAULT_USERNAME, port: int = DEFAULT_PORT, - timeout: float = DEFAULT_TIMEOUT, + timeout: float, ) -> None: """Set the constructor for this class.""" super().__init__( From bee2264cd4e02f524ff2adfdb5880adc20d9372d Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 5 Jun 2024 15:31:19 +0200 Subject: [PATCH 08/12] Corrections --- plugwise/__init__.py | 5 +++-- plugwise/legacy/smile.py | 2 +- plugwise/smile.py | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 61e611e21..57260499c 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -7,6 +7,7 @@ from plugwise.constants import ( DEFAULT_LEGACY_TIMEOUT, DEFAULT_PORT, + DEFAULT_TIMEOUT, DEFAULT_USERNAME, DOMAIN_OBJECTS, LOGGER, @@ -128,6 +129,7 @@ async def connect(self) -> bool: self._smile_api = SmileAPI( self._host, self._passwd, + self._timeout, self._websession, self._cooling_present, self._elga, @@ -147,10 +149,10 @@ async def connect(self) -> bool: self.smile_type, self._user, self._port, - self._timeout, ) if not self.smile_legacy else SmileLegacyAPI( self._host, self._passwd, + self._timeout, self._websession, self._is_thermostat, self._on_off_device, @@ -168,7 +170,6 @@ async def connect(self) -> bool: self.smile_zigbee_mac_address, self._user, self._port, - self._timeout, ) # Update all endpoints on first connect diff --git a/plugwise/legacy/smile.py b/plugwise/legacy/smile.py index 3369d951e..710ea5901 100644 --- a/plugwise/legacy/smile.py +++ b/plugwise/legacy/smile.py @@ -40,6 +40,7 @@ def __init__( self, host: str, password: str, + timeout: float, websession: aiohttp.ClientSession, _is_thermostat: bool, _on_off_device: bool, @@ -57,7 +58,6 @@ def __init__( smile_zigbee_mac_address: str | None, username: str = DEFAULT_USERNAME, port: int = DEFAULT_PORT, - timeout: float, ) -> None: """Set the constructor for this class.""" super().__init__( diff --git a/plugwise/smile.py b/plugwise/smile.py index ae612cfeb..305cbd6e0 100644 --- a/plugwise/smile.py +++ b/plugwise/smile.py @@ -46,6 +46,7 @@ def __init__( self, host: str, password: str, + timeout: float, websession: aiohttp.ClientSession, _cooling_present: bool, _elga: bool, @@ -65,7 +66,6 @@ def __init__( smile_type: str, username: str = DEFAULT_USERNAME, port: int = DEFAULT_PORT, - timeout: float, ) -> None: """Set the constructor for this class.""" super().__init__( From 10e9e2ade302370da0dc1543373b04b94a6d35fe Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 5 Jun 2024 15:47:33 +0200 Subject: [PATCH 09/12] Fix --- plugwise/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 57260499c..bbcf47510 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -57,7 +57,7 @@ def __init__( websession, username, port, - self._timeout, + timeout, ) self._host = host From 988440ab5db8f4b9bbf16b7adae6567ff399035c Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 5 Jun 2024 15:55:53 +0200 Subject: [PATCH 10/12] Bump to v0.38.2a0 test-version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index e8cfc8121..d56cc5097 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "plugwise" -version = "0.38.1" +version = "0.38.2a0" license = {file = "LICENSE"} description = "Plugwise Smile (Adam/Anna/P1) and Stretch module for Python 3." readme = "README.md" From dde95b50afcf81bfc9e8518e7500e4e7a76b9852 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 5 Jun 2024 15:57:30 +0200 Subject: [PATCH 11/12] Update CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2b0ad019..e899c9a7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v0.38.2 + +- Lower connection-timeout for actual devices after initial connect + ## v0.38.1 - Add missing exception-handling for set-function in `__init__.py` From 773b2969b38703b767322f7877e5e4e925f4d70d Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 5 Jun 2024 19:32:09 +0200 Subject: [PATCH 12/12] Bump to v0.38.2 release-version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index d56cc5097..11265ca82 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "plugwise" -version = "0.38.2a0" +version = "0.38.2" license = {file = "LICENSE"} description = "Plugwise Smile (Adam/Anna/P1) and Stretch module for Python 3." readme = "README.md"