Skip to content

Commit a2bee30

Browse files
authored
Merge pull request #637 from plugwise/timeout_cleanup
Clean up timeout-related, pass _request-function as an argument
2 parents 412cc3f + d893a1b commit a2bee30

File tree

5 files changed

+27
-44
lines changed

5 files changed

+27
-44
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+
## v1.4.3
4+
5+
- Clean up timeout-related, pass _request-function as an argument.
6+
37
## v1.4.2
48

59
- Bugfix: implement solution for issue reported in [#739](https://github.com/plugwise/plugwise-beta/issues/739)

plugwise/__init__.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from plugwise.constants import (
88
DEFAULT_PORT,
9-
DEFAULT_TIMEOUT,
109
DEFAULT_USERNAME,
1110
DOMAIN_OBJECTS,
1211
LOGGER,
@@ -61,7 +60,6 @@ def __init__(
6160
self._host = host
6261
self._passwd = password
6362
self._port = port
64-
self._timeout = timeout
6563
self._user = username
6664
self._websession = websession
6765

@@ -128,7 +126,7 @@ async def connect(self) -> bool:
128126
self._smile_api = SmileAPI(
129127
self._host,
130128
self._passwd,
131-
self._timeout,
129+
self._request,
132130
self._websession,
133131
self._cooling_present,
134132
self._elga,
@@ -152,7 +150,7 @@ async def connect(self) -> bool:
152150
) if not self.smile_legacy else SmileLegacyAPI(
153151
self._host,
154152
self._passwd,
155-
self._timeout,
153+
self._request,
156154
self._websession,
157155
self._is_thermostat,
158156
self._on_off_device,
@@ -194,9 +192,6 @@ async def _smile_detect(self, result: etree, dsmrmain: etree) -> None:
194192
else:
195193
model = await self._smile_detect_legacy(result, dsmrmain, model)
196194

197-
if not self.smile_legacy:
198-
self._timeout = DEFAULT_TIMEOUT
199-
200195
if model == "Unknown" or self.smile_fw_version is None: # pragma: no cover
201196
# Corner case check
202197
LOGGER.error(

plugwise/legacy/smile.py

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55
from __future__ import annotations
66

7+
from collections.abc import Awaitable, Callable
78
import datetime as dt
89
from typing import Any
910

@@ -24,14 +25,13 @@
2425
ThermoLoc,
2526
)
2627
from plugwise.exceptions import ConnectionFailedError, PlugwiseError
27-
from plugwise.helper import SmileComm
2828
from plugwise.legacy.data import SmileLegacyData
2929

3030
import aiohttp
3131
from munch import Munch
3232

3333

34-
class SmileLegacyAPI(SmileComm, SmileLegacyData):
34+
class SmileLegacyAPI(SmileLegacyData):
3535
"""The Plugwise SmileLegacyAPI class."""
3636

3737
# pylint: disable=too-many-instance-attributes, too-many-public-methods
@@ -40,7 +40,7 @@ def __init__(
4040
self,
4141
host: str,
4242
password: str,
43-
timeout: int,
43+
request: Callable[..., Awaitable[Any]],
4444
websession: aiohttp.ClientSession,
4545
_is_thermostat: bool,
4646
_on_off_device: bool,
@@ -60,14 +60,6 @@ def __init__(
6060
username: str = DEFAULT_USERNAME,
6161
) -> None:
6262
"""Set the constructor for this class."""
63-
super().__init__(
64-
host,
65-
password,
66-
port,
67-
timeout,
68-
username,
69-
websession,
70-
)
7163
SmileLegacyData.__init__(self)
7264

7365
self._cooling_present = False
@@ -76,8 +68,8 @@ def __init__(
7668
self._opentherm_device = _opentherm_device
7769
self._stretch_v2 = _stretch_v2
7870
self._target_smile = _target_smile
79-
self._timeout = timeout
8071
self.loc_data = loc_data
72+
self.request = request
8173
self.smile_fw_version = smile_fw_version
8274
self.smile_hostname = smile_hostname
8375
self.smile_hw_version = smile_hw_version
@@ -91,12 +83,12 @@ def __init__(
9183

9284
async def full_update_device(self) -> None:
9385
"""Perform a first fetch of all XML data, needed for initialization."""
94-
self._domain_objects = await self._request(DOMAIN_OBJECTS)
95-
self._locations = await self._request(LOCATIONS)
96-
self._modules = await self._request(MODULES)
86+
self._domain_objects = await self.request(DOMAIN_OBJECTS)
87+
self._locations = await self.request(LOCATIONS)
88+
self._modules = await self.request(MODULES)
9789
# P1 legacy has no appliances
9890
if self.smile_type != "power":
99-
self._appliances = await self._request(APPLIANCES)
91+
self._appliances = await self.request(APPLIANCES)
10092

10193
def get_all_devices(self) -> None:
10294
"""Determine the evices present from the obtained XML-data.
@@ -131,12 +123,12 @@ async def async_update(self) -> PlugwiseData:
131123
self.get_all_devices()
132124
# Otherwise perform an incremental update
133125
else:
134-
self._domain_objects = await self._request(DOMAIN_OBJECTS)
126+
self._domain_objects = await self.request(DOMAIN_OBJECTS)
135127
match self._target_smile:
136128
case "smile_v2":
137-
self._modules = await self._request(MODULES)
129+
self._modules = await self.request(MODULES)
138130
case self._target_smile if self._target_smile in REQUIRE_APPLIANCES:
139-
self._appliances = await self._request(APPLIANCES)
131+
self._appliances = await self.request(APPLIANCES)
140132

141133
self._update_gw_devices()
142134

@@ -291,10 +283,10 @@ async def set_temperature(self, _: str, items: dict[str, float]) -> None:
291283
await self.call_request(uri, method="put", data=data)
292284

293285
async def call_request(self, uri: str, **kwargs: Any) -> None:
294-
"""ConnectionFailedError wrapper for calling _request()."""
286+
"""ConnectionFailedError wrapper for calling request()."""
295287
method: str = kwargs["method"]
296288
data: str | None = kwargs.get("data")
297289
try:
298-
await self._request(uri, method=method, data=data)
290+
await self.request(uri, method=method, data=data)
299291
except ConnectionFailedError as exc:
300292
raise ConnectionFailedError from exc

plugwise/smile.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55
from __future__ import annotations
66

7+
from collections.abc import Awaitable, Callable
78
import datetime as dt
89
from typing import Any
910

@@ -28,7 +29,6 @@
2829
)
2930
from plugwise.data import SmileData
3031
from plugwise.exceptions import ConnectionFailedError, DataMissingError, PlugwiseError
31-
from plugwise.helper import SmileComm
3232

3333
import aiohttp
3434
from defusedxml import ElementTree as etree
@@ -37,7 +37,7 @@
3737
from munch import Munch
3838

3939

40-
class SmileAPI(SmileComm, SmileData):
40+
class SmileAPI(SmileData):
4141
"""The Plugwise SmileAPI helper class for actual Plugwise devices."""
4242

4343
# pylint: disable=too-many-instance-attributes, too-many-public-methods
@@ -46,7 +46,7 @@ def __init__(
4646
self,
4747
host: str,
4848
password: str,
49-
timeout: int,
49+
request: Callable[..., Awaitable[Any]],
5050
websession: aiohttp.ClientSession,
5151
_cooling_present: bool,
5252
_elga: bool,
@@ -69,14 +69,6 @@ def __init__(
6969
username: str = DEFAULT_USERNAME,
7070
) -> None:
7171
"""Set the constructor for this class."""
72-
super().__init__(
73-
host,
74-
password,
75-
port,
76-
timeout,
77-
username,
78-
websession,
79-
)
8072
SmileData.__init__(self)
8173

8274
self._cooling_present = _cooling_present
@@ -86,9 +78,9 @@ def __init__(
8678
self._on_off_device = _on_off_device
8779
self._opentherm_device = _opentherm_device
8880
self._schedule_old_states = _schedule_old_states
89-
self._timeout = timeout
9081
self.gateway_id = gateway_id
9182
self.loc_data = loc_data
83+
self.request = request
9284
self.smile_fw_version = smile_fw_version
9385
self.smile_hostname = smile_hostname
9486
self.smile_hw_version = smile_hw_version
@@ -103,7 +95,7 @@ def __init__(
10395

10496
async def full_update_device(self) -> None:
10597
"""Perform a first fetch of all XML data, needed for initialization."""
106-
self._domain_objects = await self._request(DOMAIN_OBJECTS)
98+
self._domain_objects = await self.request(DOMAIN_OBJECTS)
10799
self._get_plugwise_notifications()
108100

109101
def get_all_devices(self) -> None:
@@ -461,10 +453,10 @@ async def set_temperature(self, loc_id: str, items: dict[str, float]) -> None:
461453
await self.call_request(uri, method="put", data=data)
462454

463455
async def call_request(self, uri: str, **kwargs: Any) -> None:
464-
"""ConnectionFailedError wrapper for calling _request()."""
456+
"""ConnectionFailedError wrapper for calling request()."""
465457
method: str = kwargs["method"]
466458
data: str | None = kwargs.get("data")
467459
try:
468-
await self._request(uri, method=method, data=data)
460+
await self.request(uri, method=method, data=data)
469461
except ConnectionFailedError as exc:
470462
raise ConnectionFailedError from exc

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 = "1.4.2"
7+
version = "1.4.3"
88
license = {file = "LICENSE"}
99
description = "Plugwise Smile (Adam/Anna/P1) and Stretch module for Python 3."
1010
readme = "README.md"

0 commit comments

Comments
 (0)