Skip to content

Commit 0187ef5

Browse files
committed
Update to etree.Element typing
1 parent 4b5c84c commit 0187ef5

File tree

7 files changed

+46
-42
lines changed

7 files changed

+46
-42
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:
@@ -213,7 +215,7 @@ def _all_locations(self) -> None:
213215
f"./location[@id='{loc.loc_id}']"
214216
)
215217

216-
def _appliance_info_finder(self, appl: Munch, appliance: etree) -> Munch:
218+
def _appliance_info_finder(self, appl: Munch, appliance: etree.Element) -> Munch:
217219
"""Collect info for all appliances found."""
218220
match appl.pwclass:
219221
case "gateway":
@@ -253,7 +255,7 @@ def _appliance_info_finder(self, appl: Munch, appliance: etree) -> Munch:
253255
case _: # pragma: no cover
254256
return appl
255257

256-
def _appl_gateway_info(self, appl: Munch, appliance: etree) -> Munch:
258+
def _appl_gateway_info(self, appl: Munch, appliance: etree.Element) -> Munch:
257259
"""Helper-function for _appliance_info_finder()."""
258260
self._gateway_id = appliance.attrib["id"]
259261
appl.firmware = str(self.smile_version)
@@ -286,7 +288,7 @@ def _appl_gateway_info(self, appl: Munch, appliance: etree) -> Munch:
286288
return appl
287289

288290
def _get_appl_actuator_modes(
289-
self, appliance: etree, actuator_type: str
291+
self, appliance: etree.Element, actuator_type: str
290292
) -> list[str]:
291293
"""Get allowed modes for the given actuator type."""
292294
mode_list: list[str] = []
@@ -398,7 +400,7 @@ def _power_data_from_location(self) -> GwEntityData:
398400

399401
def _appliance_measurements(
400402
self,
401-
appliance: etree,
403+
appliance: etree.Element,
402404
data: GwEntityData,
403405
measurements: dict[str, DATA | UOM],
404406
) -> None:
@@ -430,7 +432,7 @@ def _appliance_measurements(
430432
self._count = count_data_items(self._count, data)
431433

432434
def _get_toggle_state(
433-
self, xml: etree, toggle: str, name: ToggleNameType, data: GwEntityData
435+
self, xml: etree.Element, toggle: str, name: ToggleNameType, data: GwEntityData
434436
) -> None:
435437
"""Helper-function for _get_measurement_data().
436438
@@ -459,7 +461,7 @@ def _get_plugwise_notifications(self) -> None:
459461
)
460462

461463
def _get_actuator_functionalities(
462-
self, xml: etree, entity: GwEntityData, data: GwEntityData
464+
self, xml: etree.Element, entity: GwEntityData, data: GwEntityData
463465
) -> None:
464466
"""Get and process the actuator_functionalities details for an entity.
465467
@@ -521,7 +523,7 @@ def _get_actuator_functionalities(
521523
data[act_item] = temp_dict
522524

523525
def _get_actuator_mode(
524-
self, appliance: etree, entity_id: str, key: str
526+
self, appliance: etree.Element, entity_id: str, key: str
525527
) -> str | None:
526528
"""Helper-function for _get_regulation_mode and _get_gateway_mode.
527529
@@ -536,7 +538,7 @@ def _get_actuator_mode(
536538
return None
537539

538540
def _get_regulation_mode(
539-
self, appliance: etree, entity_id: str, data: GwEntityData
541+
self, appliance: etree.Element, entity_id: str, data: GwEntityData
540542
) -> None:
541543
"""Helper-function for _get_measurement_data().
542544
@@ -552,7 +554,7 @@ def _get_regulation_mode(
552554
self._cooling_enabled = mode == "cooling"
553555

554556
def _get_gateway_mode(
555-
self, appliance: etree, entity_id: str, data: GwEntityData
557+
self, appliance: etree.Element, entity_id: str, data: GwEntityData
556558
) -> None:
557559
"""Helper-function for _get_measurement_data().
558560
@@ -838,9 +840,7 @@ def _presets(self, loc_id: str) -> dict[str, list[float]]:
838840
return presets # pragma: no cover
839841

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

plugwise/legacy/helper.py

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

5252

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

6565
def __init__(self) -> None:
6666
"""Set the constructor for this class."""
67-
self._appliances: etree
67+
self._appliances: etree.Element
6868
self._is_thermostat: bool
6969
self._loc_data: dict[str, ThermoLoc]
70-
self._locations: etree
71-
self._modules: etree
70+
self._locations: etree.Element
71+
self._modules: etree.Element
7272
self._stretch_v2: bool
7373
self.gw_entities: dict[str, GwEntityData] = {}
7474
self.smile_mac_address: str | None
@@ -318,7 +318,7 @@ def _power_data_from_modules(self) -> GwEntityData:
318318

319319
def _appliance_measurements(
320320
self,
321-
appliance: etree,
321+
appliance: etree.Element,
322322
data: GwEntityData,
323323
measurements: dict[str, DATA | UOM],
324324
) -> None:
@@ -347,7 +347,7 @@ def _appliance_measurements(
347347
self._count = count_data_items(self._count, data)
348348

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

plugwise/smile.py

Lines changed: 1 addition & 1 deletion
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)

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)