Skip to content

Commit 411551c

Browse files
authored
Merge pull request #576 from plugwise/timeout
Lower connection-timeout for actual devices after initial connect
2 parents dba5d57 + 773b296 commit 411551c

File tree

7 files changed

+20
-10
lines changed

7 files changed

+20
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v0.38.2
4+
5+
- Lower connection-timeout for actual devices after initial connect
6+
37
## v0.38.1
48

59
- Add missing exception-handling for set-function in `__init__.py`

plugwise/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from __future__ import annotations
66

77
from plugwise.constants import (
8+
DEFAULT_LEGACY_TIMEOUT,
89
DEFAULT_PORT,
910
DEFAULT_TIMEOUT,
1011
DEFAULT_USERNAME,
@@ -46,7 +47,7 @@ def __init__(
4647
websession: aiohttp.ClientSession,
4748
username: str = DEFAULT_USERNAME,
4849
port: int = DEFAULT_PORT,
49-
timeout: float = DEFAULT_TIMEOUT,
50+
timeout: float = DEFAULT_LEGACY_TIMEOUT,
5051

5152
) -> None:
5253
"""Set the constructor for this class."""
@@ -128,6 +129,7 @@ async def connect(self) -> bool:
128129
self._smile_api = SmileAPI(
129130
self._host,
130131
self._passwd,
132+
self._timeout,
131133
self._websession,
132134
self._cooling_present,
133135
self._elga,
@@ -147,10 +149,10 @@ async def connect(self) -> bool:
147149
self.smile_type,
148150
self._user,
149151
self._port,
150-
self._timeout,
151152
) if not self.smile_legacy else SmileLegacyAPI(
152153
self._host,
153154
self._passwd,
155+
self._timeout,
154156
self._websession,
155157
self._is_thermostat,
156158
self._on_off_device,
@@ -168,7 +170,6 @@ async def connect(self) -> bool:
168170
self.smile_zigbee_mac_address,
169171
self._user,
170172
self._port,
171-
self._timeout,
172173
)
173174

174175
# Update all endpoints on first connect
@@ -192,6 +193,9 @@ async def _smile_detect(self, result: etree, dsmrmain: etree) -> None:
192193
else:
193194
model = await self._smile_detect_legacy(result, dsmrmain, model)
194195

196+
if not self.smile_legacy:
197+
self._timeout = DEFAULT_TIMEOUT
198+
195199
if model == "Unknown" or self.smile_fw_version is None: # pragma: no cover
196200
# Corner case check
197201
LOGGER.error(

plugwise/constants.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232

3333
ADAM: Final = "Adam"
3434
ANNA: Final = "Smile Anna"
35-
DEFAULT_TIMEOUT: Final = 30
35+
DEFAULT_TIMEOUT: Final = 10
36+
DEFAULT_LEGACY_TIMEOUT: Final = 30
3637
DEFAULT_USERNAME: Final = "smile"
3738
DEFAULT_PORT: Final = 80
3839
DEFAULT_PW_MAX: Final = 30.0

plugwise/legacy/smile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from plugwise.constants import (
1111
APPLIANCES,
1212
DEFAULT_PORT,
13-
DEFAULT_TIMEOUT,
1413
DEFAULT_USERNAME,
1514
DOMAIN_OBJECTS,
1615
LOCATIONS,
@@ -41,6 +40,7 @@ def __init__(
4140
self,
4241
host: str,
4342
password: str,
43+
timeout: float,
4444
websession: aiohttp.ClientSession,
4545
_is_thermostat: bool,
4646
_on_off_device: bool,
@@ -58,7 +58,6 @@ def __init__(
5858
smile_zigbee_mac_address: str | None,
5959
username: str = DEFAULT_USERNAME,
6060
port: int = DEFAULT_PORT,
61-
timeout: float = DEFAULT_TIMEOUT,
6261
) -> None:
6362
"""Set the constructor for this class."""
6463
super().__init__(
@@ -77,6 +76,7 @@ def __init__(
7776
self._opentherm_device = _opentherm_device
7877
self._stretch_v2 = _stretch_v2
7978
self._target_smile = _target_smile
79+
self._timeout = timeout
8080
self.loc_data = loc_data
8181
self.smile_fw_version = smile_fw_version
8282
self.smile_hostname = smile_hostname

plugwise/smile.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
ANNA,
1313
APPLIANCES,
1414
DEFAULT_PORT,
15-
DEFAULT_TIMEOUT,
1615
DEFAULT_USERNAME,
1716
DOMAIN_OBJECTS,
1817
GATEWAY_REBOOT,
@@ -47,6 +46,7 @@ def __init__(
4746
self,
4847
host: str,
4948
password: str,
49+
timeout: float,
5050
websession: aiohttp.ClientSession,
5151
_cooling_present: bool,
5252
_elga: bool,
@@ -66,8 +66,6 @@ def __init__(
6666
smile_type: str,
6767
username: str = DEFAULT_USERNAME,
6868
port: int = DEFAULT_PORT,
69-
timeout: float = DEFAULT_TIMEOUT,
70-
7169
) -> None:
7270
"""Set the constructor for this class."""
7371
super().__init__(
@@ -87,6 +85,7 @@ def __init__(
8785
self._on_off_device = _on_off_device
8886
self._opentherm_device = _opentherm_device
8987
self._schedule_old_states = _schedule_old_states
88+
self._timeout = timeout
9089
self.gateway_id = gateway_id
9190
self.loc_data = loc_data
9291
self.smile_fw_version = smile_fw_version

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "plugwise"
7-
version = "0.38.1"
7+
version = "0.38.2"
88
license = {file = "LICENSE"}
99
description = "Plugwise Smile (Adam/Anna/P1) and Stretch module for Python 3."
1010
readme = "README.md"

tests/test_init.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,10 @@ async def device_test(
552552
await smile.full_update_device()
553553
smile.get_all_devices()
554554
data = await smile.async_update()
555+
assert smile._timeout == 30
555556
else:
556557
data = await smile.async_update()
558+
assert smile._timeout == 10
557559
else:
558560
_LOGGER.info("Asserting updated testdata:")
559561
data = await smile.async_update()

0 commit comments

Comments
 (0)