Skip to content

Commit 305ac3e

Browse files
committed
Update to etree.Element typing
1 parent 1a6d924 commit 305ac3e

File tree

7 files changed

+47
-43
lines changed

7 files changed

+47
-43
lines changed

plugwise/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@ async def connect(self) -> Version:
198198

199199
return self.smile_version
200200

201-
async def _smile_detect(self, result: etree, dsmrmain: etree) -> None:
201+
async def _smile_detect(
202+
self, result: etree.Element, dsmrmain: etree.Element
203+
) -> None:
202204
"""Helper-function for connect().
203205
204206
Detect which type of Plugwise Gateway is being connected.
@@ -256,10 +258,8 @@ async def _smile_detect(self, result: etree, dsmrmain: etree) -> None:
256258
# For Adam, Anna, determine the system capabilities:
257259
# Find the connected heating/cooling device (heater_central),
258260
# e.g. heat-pump or gas-fired heater
259-
onoff_boiler: etree = result.find("./module/protocols/onoff_boiler")
260-
open_therm_boiler: etree = result.find(
261-
"./module/protocols/open_therm_boiler"
262-
)
261+
onoff_boiler = result.find("./module/protocols/onoff_boiler")
262+
open_therm_boiler = result.find("./module/protocols/open_therm_boiler")
263263
self._on_off_device = onoff_boiler is not None
264264
self._opentherm_device = open_therm_boiler is not None
265265

@@ -272,7 +272,7 @@ async def _smile_detect(self, result: etree, dsmrmain: etree) -> None:
272272
self._elga = True
273273

274274
async def _smile_detect_legacy(
275-
self, result: etree, dsmrmain: etree, model: str
275+
self, result: etree.Element, dsmrmain: etree.Element, model: str
276276
) -> str:
277277
"""Helper-function for _smile_detect().
278278

plugwise/common.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
from munch import Munch
2828

2929

30-
def get_zigbee_data(module: etree, module_data: ModuleData, legacy: bool) -> None:
30+
def get_zigbee_data(
31+
module: etree.Element, module_data: ModuleData, legacy: bool
32+
) -> None:
3133
"""Helper-function for _get_module_data()."""
3234
if legacy:
3335
# Stretches
@@ -49,7 +51,7 @@ def __init__(self) -> None:
4951
"""Init."""
5052
self._cooling_present: bool
5153
self._count: int
52-
self._domain_objects: etree
54+
self._domain_objects: etree.Element
5355
self._heater_id: str = NONE
5456
self._on_off_device: bool
5557
self.gw_entities: dict[str, GwEntityData] = {}
@@ -63,10 +65,10 @@ def smile(self, name: str) -> bool:
6365
def _appl_heater_central_info(
6466
self,
6567
appl: Munch,
66-
xml_1: etree,
68+
xml_1: etree.Element,
6769
legacy: bool,
68-
xml_2: etree = None,
69-
xml_3: etree = None,
70+
xml_2: etree.Element = None,
71+
xml_3: etree.Element = None,
7072
) -> Munch:
7173
"""Helper-function for _appliance_info_finder()."""
7274
# Find the valid heater_central
@@ -101,7 +103,7 @@ def _appl_heater_central_info(
101103
return appl
102104

103105
def _appl_thermostat_info(
104-
self, appl: Munch, xml_1: etree, xml_2: etree = None
106+
self, appl: Munch, xml_1: etree.Element, xml_2: etree.Element = None
105107
) -> Munch:
106108
"""Helper-function for _appliance_info_finder()."""
107109
locator = "./logs/point_log[type='thermostat']/thermostat"
@@ -190,7 +192,7 @@ def _get_group_switches(self) -> dict[str, GwEntityData]:
190192
return switch_groups
191193

192194
def _get_lock_state(
193-
self, xml: etree, data: GwEntityData, stretch_v2: bool = False
195+
self, xml: etree.Element, data: GwEntityData, stretch_v2: bool = False
194196
) -> None:
195197
"""Helper-function for _get_measurement_data().
196198
@@ -209,9 +211,9 @@ def _get_lock_state(
209211

210212
def _get_module_data(
211213
self,
212-
xml_1: etree,
214+
xml_1: etree.Element,
213215
locator: str,
214-
xml_2: etree = None,
216+
xml_2: etree.Element = None,
215217
legacy: bool = False,
216218
) -> ModuleData:
217219
"""Helper-function for _energy_device_info_finder() and _appliance_info_finder().

plugwise/helper.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@
5959
from packaging import version
6060

6161

62-
def search_actuator_functionalities(appliance: etree, actuator: str) -> etree | None:
62+
def search_actuator_functionalities(
63+
appliance: etree.Element, actuator: str
64+
) -> etree.Element | None:
6365
"""Helper-function for finding the relevant actuator xml-structure."""
6466
locator = f"./actuator_functionalities/{actuator}"
6567
if (search := appliance.find(locator)) is not None:
@@ -212,7 +214,7 @@ def _all_locations(self) -> None:
212214
f"./location[@id='{loc.loc_id}']"
213215
)
214216

215-
def _appliance_info_finder(self, appl: Munch, appliance: etree) -> Munch:
217+
def _appliance_info_finder(self, appl: Munch, appliance: etree.Element) -> Munch:
216218
"""Collect info for all appliances found."""
217219
match appl.pwclass:
218220
case "gateway":
@@ -252,7 +254,7 @@ def _appliance_info_finder(self, appl: Munch, appliance: etree) -> Munch:
252254
case _: # pragma: no cover
253255
return appl
254256

255-
def _appl_gateway_info(self, appl: Munch, appliance: etree) -> Munch:
257+
def _appl_gateway_info(self, appl: Munch, appliance: etree.Element) -> Munch:
256258
"""Helper-function for _appliance_info_finder()."""
257259
self._gateway_id = appliance.attrib["id"]
258260
appl.firmware = str(self.smile_version)
@@ -285,7 +287,7 @@ def _appl_gateway_info(self, appl: Munch, appliance: etree) -> Munch:
285287
return appl
286288

287289
def _get_appl_actuator_modes(
288-
self, appliance: etree, actuator_type: str
290+
self, appliance: etree.Element, actuator_type: str
289291
) -> list[str]:
290292
"""Get allowed modes for the given actuator type."""
291293
mode_list: list[str] = []
@@ -397,7 +399,7 @@ def _power_data_from_location(self) -> GwEntityData:
397399

398400
def _appliance_measurements(
399401
self,
400-
appliance: etree,
402+
appliance: etree.Element,
401403
data: GwEntityData,
402404
measurements: dict[str, DATA | UOM],
403405
) -> None:
@@ -429,7 +431,7 @@ def _appliance_measurements(
429431
self._count = count_data_items(self._count, data)
430432

431433
def _get_toggle_state(
432-
self, xml: etree, toggle: str, name: ToggleNameType, data: GwEntityData
434+
self, xml: etree.Element, toggle: str, name: ToggleNameType, data: GwEntityData
433435
) -> None:
434436
"""Helper-function for _get_measurement_data().
435437
@@ -458,7 +460,7 @@ def _get_plugwise_notifications(self) -> None:
458460
)
459461

460462
def _get_actuator_functionalities(
461-
self, xml: etree, entity: GwEntityData, data: GwEntityData
463+
self, xml: etree.Element, entity: GwEntityData, data: GwEntityData
462464
) -> None:
463465
"""Get and process the actuator_functionalities details for an entity.
464466
@@ -520,7 +522,7 @@ def _get_actuator_functionalities(
520522
data[act_item] = temp_dict
521523

522524
def _get_actuator_mode(
523-
self, appliance: etree, entity_id: str, key: str
525+
self, appliance: etree.Element, entity_id: str, key: str
524526
) -> str | None:
525527
"""Helper-function for _get_regulation_mode and _get_gateway_mode.
526528
@@ -535,7 +537,7 @@ def _get_actuator_mode(
535537
return None
536538

537539
def _get_regulation_mode(
538-
self, appliance: etree, entity_id: str, data: GwEntityData
540+
self, appliance: etree.Element, entity_id: str, data: GwEntityData
539541
) -> None:
540542
"""Helper-function for _get_measurement_data().
541543
@@ -551,7 +553,7 @@ def _get_regulation_mode(
551553
self._cooling_enabled = mode == "cooling"
552554

553555
def _get_gateway_mode(
554-
self, appliance: etree, entity_id: str, data: GwEntityData
556+
self, appliance: etree.Element, entity_id: str, data: GwEntityData
555557
) -> None:
556558
"""Helper-function for _get_measurement_data().
557559
@@ -837,9 +839,7 @@ def _presets(self, loc_id: str) -> dict[str, list[float]]:
837839
return presets # pragma: no cover
838840

839841
for rule_id in rule_ids:
840-
directives: etree = self._domain_objects.find(
841-
f'rule[@id="{rule_id}"]/directives'
842-
)
842+
directives = self._domain_objects.find(f'rule[@id="{rule_id}"]/directives')
843843
for directive in directives:
844844
preset = directive.find("then").attrib
845845
presets[directive.attrib["preset"]] = [

plugwise/legacy/helper.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
from packaging.version import Version
5050

5151

52-
def etree_to_dict(element: etree) -> dict[str, str]:
52+
def etree_to_dict(element: etree.Element) -> dict[str, str]:
5353
"""Helper-function translating xml Element to dict."""
5454
node: dict[str, str] = {}
5555
if element is not None:
@@ -63,11 +63,11 @@ class SmileLegacyHelper(SmileCommon):
6363

6464
def __init__(self) -> None:
6565
"""Set the constructor for this class."""
66-
self._appliances: etree
66+
self._appliances: etree.Element
6767
self._is_thermostat: bool
6868
self._loc_data: dict[str, ThermoLoc]
69-
self._locations: etree
70-
self._modules: etree
69+
self._locations: etree.Element
70+
self._modules: etree.Element
7171
self._stretch_v2: bool
7272
self.gw_entities: dict[str, GwEntityData] = {}
7373
self.smile_mac_address: str | None
@@ -316,7 +316,7 @@ def _power_data_from_modules(self) -> GwEntityData:
316316

317317
def _appliance_measurements(
318318
self,
319-
appliance: etree,
319+
appliance: etree.Element,
320320
data: GwEntityData,
321321
measurements: dict[str, DATA | UOM],
322322
) -> None:
@@ -345,7 +345,7 @@ def _appliance_measurements(
345345
self._count = count_data_items(self._count, data)
346346

347347
def _get_actuator_functionalities(
348-
self, xml: etree, entity: GwEntityData, data: GwEntityData
348+
self, xml: etree.Element, entity: GwEntityData, data: GwEntityData
349349
) -> None:
350350
"""Helper-function for _get_measurement_data()."""
351351
for item in ACTIVE_ACTUATORS:

plugwise/smile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ async def set_schedule_state(
355355

356356
def determine_contexts(
357357
self, loc_id: str, name: str, state: str, sched_id: str
358-
) -> etree:
358+
) -> etree.Element:
359359
"""Helper-function for set_schedule_state()."""
360360
locator = f'.//*[@id="{sched_id}"]/contexts'
361361
contexts = self._domain_objects.find(locator)
@@ -399,7 +399,7 @@ async def set_switch_state(
399399
return await self._set_groupswitch_member_state(members, state, switch)
400400

401401
locator = f'appliance[@id="{appl_id}"]/{switch.actuator}/{switch.func_type}'
402-
found: list[etree] = self._domain_objects.findall(locator)
402+
found = self._domain_objects.findall(locator)
403403
for item in found:
404404
if (sw_type := item.find("type")) is not None:
405405
if sw_type.text == switch.act_type:

plugwise/smilecomm.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ async def _request(
5151
retry: int = 3,
5252
method: str = "get",
5353
data: str | None = None,
54-
) -> etree:
54+
) -> etree.Element:
5555
"""Get/put/delete data from a give URL."""
5656
resp: ClientResponse
5757
url = f"{self._endpoint}{command}"
@@ -107,7 +107,9 @@ async def _request(
107107

108108
return await self._request_validate(resp, method)
109109

110-
async def _request_validate(self, resp: ClientResponse, method: str) -> etree:
110+
async def _request_validate(
111+
self, resp: ClientResponse, method: str
112+
) -> etree.Element:
111113
"""Helper-function for _request(): validate the returned data."""
112114
match resp.status:
113115
case 200:

plugwise/util.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def in_alternative_location(loc: Munch, legacy: bool) -> bool:
7474
return present
7575

7676

77-
def check_heater_central(xml: etree) -> str:
77+
def check_heater_central(xml: etree.Element) -> str:
7878
"""Find the valid heater_central, helper-function for _appliance_info_finder().
7979
8080
Solution for Core Issue #104433,
@@ -143,7 +143,7 @@ def collect_power_values(
143143
def common_match_cases(
144144
measurement: str,
145145
attrs: DATA | UOM,
146-
location: etree,
146+
location: etree.Element,
147147
data: GwEntityData,
148148
) -> None:
149149
"""Helper-function for common match-case execution."""
@@ -213,7 +213,7 @@ def format_measure(measure: str, unit: str) -> float | int:
213213
return result
214214

215215

216-
def get_vendor_name(module: etree, model_data: ModuleData) -> ModuleData:
216+
def get_vendor_name(module: etree.Element, model_data: ModuleData) -> ModuleData:
217217
"""Helper-function for _get_model_data()."""
218218
if (vendor_name := module.find("vendor_name").text) is not None:
219219
model_data["vendor_name"] = vendor_name
@@ -302,12 +302,12 @@ def remove_empty_platform_dicts(data: GwEntityData) -> None:
302302
data.pop("switches")
303303

304304

305-
def return_valid(value: etree | None, default: etree) -> etree:
305+
def return_valid(value: etree.Element | None, default: etree.Element) -> etree.Element:
306306
"""Return default when value is None."""
307307
return value if value is not None else default
308308

309309

310-
def skip_obsolete_measurements(xml: etree, measurement: str) -> bool:
310+
def skip_obsolete_measurements(xml: etree.Element, measurement: str) -> bool:
311311
"""Skipping known obsolete measurements."""
312312
locator = f".//logs/point_log[type='{measurement}']/updated_date"
313313
if (

0 commit comments

Comments
 (0)