Skip to content

Commit 0d24833

Browse files
committed
Add more typing
1 parent c915cd9 commit 0d24833

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

plugwise/helper.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@
88
from typing import Any
99

1010
# This way of importing aiohttp is because of patch/mocking in testing (aiohttp timeouts)
11-
from aiohttp import BasicAuth, ClientSession, ClientTimeout, ServerTimeoutError
11+
from aiohttp import (
12+
BasicAuth,
13+
ClientResponse,
14+
ClientSession,
15+
ClientTimeout,
16+
ServerTimeoutError,
17+
)
1218
from dateutil.parser import parse
1319
from defusedxml import ElementTree as etree
1420
from munch import Munch
@@ -76,7 +82,7 @@ def check_model(name, v_name) -> str:
7682
if v_name in ["Plugwise", "Plugwise B.V."]:
7783
if name == "ThermoTouch":
7884
return "Anna"
79-
model = version_to_model(name)
85+
model: str = version_to_model(name)
8086
if model != "Unknown":
8187
return model
8288
else:
@@ -137,9 +143,9 @@ def types_finder(data) -> set:
137143
return types
138144

139145

140-
def power_data_local_format(attrs, key_string, val) -> float | int:
146+
def power_data_local_format(attrs, key_string, val) -> float | int | str:
141147
"""Format power data."""
142-
f_val: float | int = format_measure(val, attrs[ATTR_UNIT_OF_MEASUREMENT])
148+
f_val: float | int | str = format_measure(val, attrs[ATTR_UNIT_OF_MEASUREMENT])
143149
# Format only HOME_MEASUREMENT POWER_WATT values, do not move to util-format_meaure function!
144150
if attrs[ATTR_UNIT_OF_MEASUREMENT] == POWER_WATT:
145151
f_val = int(round(float(val)))
@@ -203,7 +209,7 @@ async def _create_session() -> ClientSession:
203209
self._endpoint: str = f"http://{host}:{str(port)}"
204210
self._timeout: str = timeout
205211

206-
async def _request_validate(self, resp, method):
212+
async def _request_validate(self, resp, method) -> etree:
207213
"""Helper-function for _request(): validate the returned data."""
208214
# Command accepted gives empty body with status 202
209215
if resp.status == 202:
@@ -215,14 +221,14 @@ async def _request_validate(self, resp, method):
215221
if resp.status == 401:
216222
raise InvalidAuthentication
217223

218-
result = await resp.text()
224+
result: str = await resp.text()
219225
if not result or "<error>" in result:
220226
LOGGER.error("Smile response empty or error in %s", result)
221227
raise ResponseError
222228

223229
try:
224230
# Encode to ensure utf8 parsing
225-
xml = etree.XML(escape_illegal_xml_characters(result).encode())
231+
xml: etree = etree.XML(escape_illegal_xml_characters(result).encode())
226232
except etree.ParseError:
227233
LOGGER.error("Smile returns invalid XML for %s", self._endpoint)
228234
raise InvalidXMLError
@@ -236,9 +242,9 @@ async def _request(
236242
method: str = "get",
237243
data: str = None,
238244
headers: dict[str, str] = None,
239-
):
245+
) -> etree:
240246
"""Get/put/delete data from a give URL."""
241-
resp = None
247+
resp: ClientResponse = None
242248
url: str = f"{self._endpoint}{command}"
243249

244250
try:

0 commit comments

Comments
 (0)