Skip to content

Commit b241633

Browse files
committed
Add more typing hints
1 parent af8bd37 commit b241633

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

plugwise/helper.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def _locations_legacy(self) -> None:
327327
"members": appliances,
328328
}
329329

330-
def _locations_specials(self, loc, location):
330+
def _locations_specials(self, loc, location) -> Munch:
331331
"""Helper-function for _all_locations().
332332
Correct location info in special cases.
333333
"""
@@ -616,11 +616,11 @@ def _all_appliances(self) -> None:
616616
):
617617
self._appl_data.pop(appl.dev_id)
618618

619-
def _match_locations(self):
619+
def _match_locations(self) -> dict[str, Any]:
620620
"""Helper-function for _scan_thermostats().
621621
Update locations with present appliance-types.
622622
"""
623-
matched_locations = {}
623+
matched_locations: dict[str, Any] = {}
624624

625625
self._all_appliances()
626626
for location_id, location_details in self._loc_data.items():
@@ -630,13 +630,13 @@ def _match_locations(self):
630630

631631
return matched_locations
632632

633-
def _control_state(self, loc_id):
633+
def _control_state(self, loc_id) -> str | None:
634634
"""Helper-function for _device_data_climate().
635635
Adam: find the thermostat control_state of a location, from DOMAIN_OBJECTS.
636636
Represents the heating/cooling demand-state of the local master thermostat.
637637
Note: heating or cooling can still be active when the setpoint has been reached.
638638
"""
639-
locator = f'location[@id="{loc_id}"]'
639+
locator: str = f'location[@id="{loc_id}"]'
640640
if (location := self._domain_objects.find(locator)) is not None:
641641
locator = (
642642
".//actuator_functionalities/thermostat_functionality/control_state"
@@ -646,9 +646,9 @@ def _control_state(self, loc_id):
646646

647647
return
648648

649-
def _presets_legacy(self):
649+
def _presets_legacy(self) -> dict[str, Any]:
650650
"""Helper-function for presets() - collect Presets for a legacy Anna."""
651-
preset_dictionary = {}
651+
preset_dictionary: dict[str, Any] = {}
652652
for directive in self._domain_objects.findall("rule/directives/when/then"):
653653
if directive is not None and "icon" in directive.keys():
654654
# Ensure list of heating_setpoint, cooling_setpoint
@@ -659,11 +659,11 @@ def _presets_legacy(self):
659659

660660
return preset_dictionary
661661

662-
def _presets(self, loc_id):
662+
def _presets(self, loc_id) -> dict[str, Any]:
663663
"""Collect Presets for a Thermostat based on location_id."""
664-
presets = {}
665-
tag_1 = "zone_setpoint_and_state_based_on_preset"
666-
tag_2 = "Thermostat presets"
664+
presets: dict[str, Any] = {}
665+
tag_1: str = "zone_setpoint_and_state_based_on_preset"
666+
tag_2: str = "Thermostat presets"
667667

668668
if self._smile_legacy:
669669
return self._presets_legacy()
@@ -673,10 +673,12 @@ def _presets(self, loc_id):
673673
return presets # pragma: no cover
674674

675675
for rule_id in rule_ids:
676-
directives = self._domain_objects.find(f'rule[@id="{rule_id}"]/directives')
676+
directives: etree = self._domain_objects.find(
677+
f'rule[@id="{rule_id}"]/directives'
678+
)
677679

678680
for directive in directives:
679-
preset = directive.find("then").attrib
681+
preset: str = directive.find("then").attrib
680682
keys, dummy = zip(*preset.items())
681683
if str(keys[0]) == "setpoint":
682684
presets[directive.attrib["preset"]] = [float(preset["setpoint"]), 0]
@@ -688,12 +690,12 @@ def _presets(self, loc_id):
688690

689691
return presets
690692

691-
def _rule_ids_by_name(self, name, loc_id):
693+
def _rule_ids_by_name(self, name, loc_id) -> dict[str]:
692694
"""Helper-function for _presets().
693695
Obtain the rule_id from the given name and and provide the location_id, when present.
694696
"""
695-
schema_ids = {}
696-
locator = f'.//contexts/context/zone/location[@id="{loc_id}"]'
697+
schema_ids: dict[str] = {}
698+
locator: str = f'.//contexts/context/zone/location[@id="{loc_id}"]'
697699
for rule in self._domain_objects.findall(f'.//rule[name="{name}"]'):
698700
if rule.find(locator) is not None:
699701
schema_ids[rule.attrib["id"]] = loc_id
@@ -702,13 +704,13 @@ def _rule_ids_by_name(self, name, loc_id):
702704

703705
return schema_ids
704706

705-
def _rule_ids_by_tag(self, tag, loc_id):
707+
def _rule_ids_by_tag(self, tag, loc_id) -> dict[str]:
706708
"""Helper-function for _presets(), _schemas() and _last_active_schema().
707709
Obtain the rule_id from the given template_tag and provide the location_id, when present.
708710
"""
709-
schema_ids = {}
710-
locator1 = f'.//template[@tag="{tag}"]'
711-
locator2 = f'.//contexts/context/zone/location[@id="{loc_id}"]'
711+
schema_ids: dict[str] = {}
712+
locator1: str = f'.//template[@tag="{tag}"]'
713+
locator2: str = f'.//contexts/context/zone/location[@id="{loc_id}"]'
712714
for rule in self._domain_objects.findall(".//rule"):
713715
if rule.find(locator1) is not None:
714716
if rule.find(locator2) is not None:

0 commit comments

Comments
 (0)