From 133853cbc7f81b39dcf8c566238e333002da55af Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Tue, 24 Sep 2024 19:42:03 +0200 Subject: [PATCH 01/15] Remove timeout as input, determine based on username --- plugwise/__init__.py | 10 ---------- plugwise/helper.py | 8 +++++++- plugwise/legacy/helper.py | 1 - plugwise/legacy/smile.py | 3 --- plugwise/smile.py | 3 --- 5 files changed, 7 insertions(+), 18 deletions(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index b1aac2301..35cc2f4e2 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -5,9 +5,7 @@ from __future__ import annotations from plugwise.constants import ( - DEFAULT_LEGACY_TIMEOUT, DEFAULT_PORT, - DEFAULT_TIMEOUT, DEFAULT_USERNAME, DOMAIN_OBJECTS, LOGGER, @@ -47,7 +45,6 @@ def __init__( websession: aiohttp.ClientSession, username: str = DEFAULT_USERNAME, port: int = DEFAULT_PORT, - timeout: float = DEFAULT_LEGACY_TIMEOUT, ) -> None: """Set the constructor for this class.""" @@ -57,7 +54,6 @@ def __init__( websession, username, port, - timeout, ) self._host = host @@ -65,7 +61,6 @@ def __init__( self._websession = websession self._user = username self._port = port - self._timeout = timeout self._cooling_present = False self._elga = False @@ -130,7 +125,6 @@ async def connect(self) -> bool: self._smile_api = SmileAPI( self._host, self._passwd, - self._timeout, self._websession, self._cooling_present, self._elga, @@ -154,7 +148,6 @@ async def connect(self) -> bool: ) if not self.smile_legacy else SmileLegacyAPI( self._host, self._passwd, - self._timeout, self._websession, self._is_thermostat, self._on_off_device, @@ -196,9 +189,6 @@ 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( diff --git a/plugwise/helper.py b/plugwise/helper.py index bea10938e..baba95cfd 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -16,6 +16,9 @@ ANNA, ATTR_NAME, DATA, + DEFAULT_USERNAME, + DEFAULT_TIMEOUT, + DEFAULT_LEGACY_TIMEOUT, DEVICE_MEASUREMENTS, DHW_SETPOINT, DOMAIN_OBJECTS, @@ -74,9 +77,12 @@ def __init__( websession: ClientSession | None, username: str, port: int, - timeout: float, ) -> None: """Set the constructor for this class.""" + timeout = DEFAULT_TIMEOUT + if username != DEFAULT_USERNAME: + timeout = DEFAULT_LEGACY_TIMEOUT + if not websession: aio_timeout = ClientTimeout(total=timeout) diff --git a/plugwise/legacy/helper.py b/plugwise/legacy/helper.py index c50e65637..642bbd951 100644 --- a/plugwise/legacy/helper.py +++ b/plugwise/legacy/helper.py @@ -41,7 +41,6 @@ version_to_model, ) -# This way of importing aiohttp is because of patch/mocking in testing (aiohttp timeouts) from defusedxml import ElementTree as etree from munch import Munch diff --git a/plugwise/legacy/smile.py b/plugwise/legacy/smile.py index 710ea5901..2e3d37a68 100644 --- a/plugwise/legacy/smile.py +++ b/plugwise/legacy/smile.py @@ -40,7 +40,6 @@ def __init__( self, host: str, password: str, - timeout: float, websession: aiohttp.ClientSession, _is_thermostat: bool, _on_off_device: bool, @@ -66,7 +65,6 @@ def __init__( websession, username, port, - timeout, ) SmileLegacyData.__init__(self) @@ -76,7 +74,6 @@ 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 1807ca5cd..055bd466a 100644 --- a/plugwise/smile.py +++ b/plugwise/smile.py @@ -46,7 +46,6 @@ def __init__( self, host: str, password: str, - timeout: float, websession: aiohttp.ClientSession, _cooling_present: bool, _elga: bool, @@ -75,7 +74,6 @@ def __init__( websession, username, port, - timeout, ) SmileData.__init__(self) @@ -86,7 +84,6 @@ 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 85421a434c4a6a8998c312c0abd0c3c685f19d18 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Tue, 24 Sep 2024 19:45:55 +0200 Subject: [PATCH 02/15] Update non-legacy timeout assert --- tests/test_init.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_init.py b/tests/test_init.py index ba437a561..fc62afcb6 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -339,7 +339,7 @@ async def connect( ) if not timeout: - assert smile._timeout == 30 + assert smile._timeout == 10 # Connect to the smile try: From c44aa257589817b1ed96e011812d7feaf864b7fd Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Tue, 24 Sep 2024 19:48:30 +0200 Subject: [PATCH 03/15] Improve timeout test-assert for legacy --- plugwise/helper.py | 4 ++-- tests/test_init.py | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index baba95cfd..2e78e7a4d 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -17,8 +17,8 @@ ATTR_NAME, DATA, DEFAULT_USERNAME, - DEFAULT_TIMEOUT, DEFAULT_LEGACY_TIMEOUT, + DEFAULT_TIMEOUT, DEVICE_MEASUREMENTS, DHW_SETPOINT, DOMAIN_OBJECTS, @@ -79,7 +79,7 @@ def __init__( port: int, ) -> None: """Set the constructor for this class.""" - timeout = DEFAULT_TIMEOUT + timeout = DEFAULT_TIMEOUT if username != DEFAULT_USERNAME: timeout = DEFAULT_LEGACY_TIMEOUT diff --git a/tests/test_init.py b/tests/test_init.py index fc62afcb6..c6e2e051a 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -397,10 +397,14 @@ async def connect_legacy( assert "xml" in text # Test lack of websession + user_name = pw_constants.DEFAULT_USERNAME + if stretch: + user_name = pw_constants.STRETCH + try: smile = pw_smile.Smile( host=server.host, - username=pw_constants.DEFAULT_USERNAME, + username=user_name, password=test_password, port=server.port, websession=None, @@ -413,14 +417,17 @@ async def connect_legacy( smile = pw_smile.Smile( host=server.host, - username=pw_constants.DEFAULT_USERNAME, + username=user_name, password=test_password, port=server.port, websession=websession, ) if not timeout: - assert smile._timeout == 30 + if smile.smile_type == pw_constants.STRETCH: + assert smile._timeout == 30 + else: + assert smile._timeout == 10 # Connect to the smile try: @@ -552,7 +559,10 @@ async def device_test( await smile.full_update_device() smile.get_all_devices() data = await smile.async_update() - assert smile._timeout == 30 + if smile.smile_type == pw_constants.STRETCH: + assert smile._timeout == 30 + else: + assert smile._timeout == 10 else: data = await smile.async_update() assert smile._timeout == 10 From 71f01ecdfc1cf8c5bb949939f177b9ef09b8df75 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Tue, 24 Sep 2024 20:22:44 +0200 Subject: [PATCH 04/15] Debug --- tests/test_init.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_init.py b/tests/test_init.py index c6e2e051a..d0b14a400 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -400,6 +400,7 @@ async def connect_legacy( user_name = pw_constants.DEFAULT_USERNAME if stretch: user_name = pw_constants.STRETCH + _LOGGER.debug("HOI username: %s", user_name) try: smile = pw_smile.Smile( @@ -424,6 +425,7 @@ async def connect_legacy( ) if not timeout: + _LOGGER.debug("HOI type: %s", smile_type) if smile.smile_type == pw_constants.STRETCH: assert smile._timeout == 30 else: From d836455fecec59b95e303f1a3dfddfc72e481119 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Tue, 24 Sep 2024 20:25:13 +0200 Subject: [PATCH 05/15] Fix --- tests/test_init.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_init.py b/tests/test_init.py index d0b14a400..3773848e5 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -425,7 +425,7 @@ async def connect_legacy( ) if not timeout: - _LOGGER.debug("HOI type: %s", smile_type) + _LOGGER.debug("HOI type: %s", smile.smile_type) if smile.smile_type == pw_constants.STRETCH: assert smile._timeout == 30 else: From 18ff7c9935a640f374475bfff795c761ec04128c Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 25 Sep 2024 07:54:42 +0200 Subject: [PATCH 06/15] Extra debug --- plugwise/helper.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugwise/helper.py b/plugwise/helper.py index 2e78e7a4d..43980d49c 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -79,6 +79,7 @@ def __init__( port: int, ) -> None: """Set the constructor for this class.""" + LOGGER.debug("HOI username in: %s", username) timeout = DEFAULT_TIMEOUT if username != DEFAULT_USERNAME: timeout = DEFAULT_LEGACY_TIMEOUT From 61350641628b6504de970b712f04f18ea155d7b4 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 25 Sep 2024 08:03:25 +0200 Subject: [PATCH 07/15] Move up --- tests/test_init.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/test_init.py b/tests/test_init.py index 3773848e5..20aa1e36a 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -367,6 +367,10 @@ async def connect_legacy( test_password = "".join( secrets.choice(string.ascii_lowercase) for _ in range(8) ) + user_name = pw_constants.DEFAULT_USERNAME + if stretch: + user_name = pw_constants.STRETCH + _LOGGER.debug("HOI username: %s", user_name) # Happy flow app = await self.setup_legacy_app(broken, timeout, raise_timeout, fail_auth, stretch) @@ -397,11 +401,6 @@ async def connect_legacy( assert "xml" in text # Test lack of websession - user_name = pw_constants.DEFAULT_USERNAME - if stretch: - user_name = pw_constants.STRETCH - _LOGGER.debug("HOI username: %s", user_name) - try: smile = pw_smile.Smile( host=server.host, From a33dd52c14607dcbae0f29389d9e4fea367603fb Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 25 Sep 2024 08:11:45 +0200 Subject: [PATCH 08/15] Try fix --- tests/test_init.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_init.py b/tests/test_init.py index 20aa1e36a..97073e1aa 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -487,19 +487,19 @@ async def connect_legacy_wrapper( """Wrap connect to try negative testing before positive testing.""" if raise_timeout: _LOGGER.warning("Connecting to device exceeding timeout in handling:") - return await self.connect_legacy(raise_timeout=True) + return await self.connect_legacy(raise_timeout=True, stretch=stretch) try: _LOGGER.warning("Connecting to device exceeding timeout in response:") - await self.connect_legacy(timeout=True) + await self.connect_legacy(timeout=True, stretch=stretch) _LOGGER.error(" - timeout not handled") # pragma: no cover raise self.ConnectError # pragma: no cover except pw_exceptions.ConnectionFailedError: _LOGGER.info(" + successfully passed timeout handling.") try: - _LOGGER.warning("Connecting to device with missing data:") - await self.connect_legacy(broken=True) + _LOGGER.warning("Connecting to device, with missing data:") + await self.connect_legacy(broken=True, stretch=stretch) _LOGGER.error(" - broken information not handled") # pragma: no cover raise self.ConnectError # pragma: no cover except pw_exceptions.InvalidXMLError: From a4fde31ccd6592f42430aa649e9acb55a9aa7eb4 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 25 Sep 2024 08:15:44 +0200 Subject: [PATCH 09/15] Type is None, use user_name --- tests/test_init.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_init.py b/tests/test_init.py index 97073e1aa..e7c23f667 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -424,8 +424,8 @@ async def connect_legacy( ) if not timeout: - _LOGGER.debug("HOI type: %s", smile.smile_type) - if smile.smile_type == pw_constants.STRETCH: + _LOGGER.debug("HOI type: %s", user_name) + if user_name == pw_constants.STRETCH: assert smile._timeout == 30 else: assert smile._timeout == 10 From fd2b12213a68c14d50fef41b795156539983368b Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 25 Sep 2024 08:18:07 +0200 Subject: [PATCH 10/15] Fix sorting --- plugwise/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index 43980d49c..b54728acb 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -16,9 +16,9 @@ ANNA, ATTR_NAME, DATA, - DEFAULT_USERNAME, DEFAULT_LEGACY_TIMEOUT, DEFAULT_TIMEOUT, + DEFAULT_USERNAME, DEVICE_MEASUREMENTS, DHW_SETPOINT, DOMAIN_OBJECTS, From 5db0b0920323194b5c64f04d73738ae21a61ccd7 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 25 Sep 2024 08:19:10 +0200 Subject: [PATCH 11/15] Remove debugging --- plugwise/helper.py | 1 - tests/test_init.py | 2 -- 2 files changed, 3 deletions(-) diff --git a/plugwise/helper.py b/plugwise/helper.py index b54728acb..1f679c0b8 100644 --- a/plugwise/helper.py +++ b/plugwise/helper.py @@ -79,7 +79,6 @@ def __init__( port: int, ) -> None: """Set the constructor for this class.""" - LOGGER.debug("HOI username in: %s", username) timeout = DEFAULT_TIMEOUT if username != DEFAULT_USERNAME: timeout = DEFAULT_LEGACY_TIMEOUT diff --git a/tests/test_init.py b/tests/test_init.py index e7c23f667..c41d9a0de 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -370,7 +370,6 @@ async def connect_legacy( user_name = pw_constants.DEFAULT_USERNAME if stretch: user_name = pw_constants.STRETCH - _LOGGER.debug("HOI username: %s", user_name) # Happy flow app = await self.setup_legacy_app(broken, timeout, raise_timeout, fail_auth, stretch) @@ -424,7 +423,6 @@ async def connect_legacy( ) if not timeout: - _LOGGER.debug("HOI type: %s", user_name) if user_name == pw_constants.STRETCH: assert smile._timeout == 30 else: From f2743315d4c9ce12f15bff22b8ba63752d8df0e4 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 25 Sep 2024 09:16:11 +0200 Subject: [PATCH 12/15] Test-init: remove stretch argument in non-legacy functions --- tests/test_init.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/test_init.py b/tests/test_init.py index c41d9a0de..aecb7c4e8 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -87,7 +87,6 @@ async def setup_app( timeout=False, raise_timeout=False, fail_auth=False, - stretch=False, ): """Create mock webserver for Smile to interface with.""" app = aiohttp.web.Application() @@ -279,7 +278,6 @@ async def connect( timeout=False, raise_timeout=False, fail_auth=False, - stretch=False, ): """Connect to a smile environment and perform basic asserts.""" port = aiohttp.test_utils.unused_port() @@ -288,7 +286,7 @@ async def connect( ) # Happy flow - app = await self.setup_app(broken, timeout, raise_timeout, fail_auth, stretch) + app = await self.setup_app(broken, timeout, raise_timeout, fail_auth) server = aiohttp.test_utils.TestServer( app, port=port, scheme="http", host="127.0.0.1" @@ -443,7 +441,7 @@ async def connect_legacy( # Wrap connect for invalid connections async def connect_wrapper( - self, raise_timeout=False, fail_auth=False, stretch=False + self, raise_timeout=False, fail_auth=False, ): """Wrap connect to try negative testing before positive testing.""" if fail_auth: @@ -477,7 +475,7 @@ async def connect_wrapper( _LOGGER.info(" + successfully passed XML issue handling.") _LOGGER.info("Connecting to functioning device:") - return await self.connect(stretch=stretch) + return await self.connect() async def connect_legacy_wrapper( self, raise_timeout=False, fail_auth=False, stretch=False From 43c9ddeea75058a2b251e58b4196d4837a9a3cfc Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 25 Sep 2024 10:27:28 +0200 Subject: [PATCH 13/15] Rename to _username, implement in test --- plugwise/__init__.py | 6 +++--- tests/test_init.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 35cc2f4e2..3a481126f 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -59,7 +59,7 @@ def __init__( self._host = host self._passwd = password self._websession = websession - self._user = username + self._username = username self._port = port self._cooling_present = False @@ -143,7 +143,7 @@ async def connect(self) -> bool: self.smile_model_id, self.smile_name, self.smile_type, - self._user, + self._username, self._port, ) if not self.smile_legacy else SmileLegacyAPI( self._host, @@ -163,7 +163,7 @@ async def connect(self) -> bool: self.smile_name, self.smile_type, self.smile_zigbee_mac_address, - self._user, + self._username, self._port, ) diff --git a/tests/test_init.py b/tests/test_init.py index aecb7c4e8..da1476bdd 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -556,7 +556,7 @@ async def device_test( await smile.full_update_device() smile.get_all_devices() data = await smile.async_update() - if smile.smile_type == pw_constants.STRETCH: + if smile._username == pw_constants.STRETCH: assert smile._timeout == 30 else: assert smile._timeout == 10 From d34af434898b7f2783f3c958336cde46a6fcc219 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 25 Sep 2024 11:21:44 +0200 Subject: [PATCH 14/15] Bump to v1.4.2a0 test-version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 64e81edae..5022b54d5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "plugwise" -version = "1.4.1" +version = "1.4.2a0" license = {file = "LICENSE"} description = "Plugwise Smile (Adam/Anna/P1) and Stretch module for Python 3." readme = "README.md" From ce6de3de6380310bbb8f8a9114a581c381106091 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 25 Sep 2024 11:24:42 +0200 Subject: [PATCH 15/15] Update CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 967f18b15..0e9ad0160 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v1.4.2 + +- Improve timeout setting: set it to 30s for the Stretch, to 10s for all other devices. + ## v1.4.1 - Prettying documents with Biome (CLI), fixture layout updated accordingly.