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` diff --git a/plugwise/__init__.py b/plugwise/__init__.py index 7faef69a6..bbcf47510 100644 --- a/plugwise/__init__.py +++ b/plugwise/__init__.py @@ -5,6 +5,7 @@ from __future__ import annotations from plugwise.constants import ( + DEFAULT_LEGACY_TIMEOUT, DEFAULT_PORT, DEFAULT_TIMEOUT, DEFAULT_USERNAME, @@ -46,7 +47,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.""" @@ -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 @@ -192,6 +193,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( 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 diff --git a/plugwise/legacy/smile.py b/plugwise/legacy/smile.py index e72621b82..710ea5901 100644 --- a/plugwise/legacy/smile.py +++ b/plugwise/legacy/smile.py @@ -10,7 +10,6 @@ from plugwise.constants import ( APPLIANCES, DEFAULT_PORT, - DEFAULT_TIMEOUT, DEFAULT_USERNAME, DOMAIN_OBJECTS, LOCATIONS, @@ -41,6 +40,7 @@ def __init__( self, host: str, password: str, + timeout: float, websession: aiohttp.ClientSession, _is_thermostat: bool, _on_off_device: bool, @@ -58,7 +58,6 @@ def __init__( smile_zigbee_mac_address: str | None, username: str = DEFAULT_USERNAME, port: int = DEFAULT_PORT, - timeout: float = DEFAULT_TIMEOUT, ) -> None: """Set the constructor for this class.""" super().__init__( @@ -77,6 +76,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..305cbd6e0 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, @@ -47,6 +46,7 @@ def __init__( self, host: str, password: str, + timeout: float, websession: aiohttp.ClientSession, _cooling_present: bool, _elga: bool, @@ -66,8 +66,6 @@ def __init__( smile_type: str, username: str = DEFAULT_USERNAME, port: int = DEFAULT_PORT, - timeout: float = DEFAULT_TIMEOUT, - ) -> None: """Set the constructor for this class.""" super().__init__( @@ -87,6 +85,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 diff --git a/pyproject.toml b/pyproject.toml index e8cfc8121..11265ca82 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.2" license = {file = "LICENSE"} description = "Plugwise Smile (Adam/Anna/P1) and Stretch module for Python 3." readme = "README.md" 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()