Skip to content

Commit 8962ed6

Browse files
committed
Helper.py: add typing hints for all arguments of methods
1 parent 27eee24 commit 8962ed6

File tree

1 file changed

+63
-34
lines changed

1 file changed

+63
-34
lines changed

plugwise/helper.py

Lines changed: 63 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@
5757
)
5858

5959

60-
def pw_notification_updater(devs, d_id, d_dict, notifs) -> None:
60+
def pw_notification_updater(
61+
devs: dict[str, Any], d_id: str, d_dict: dict[str, Any], notifs: dict[str, str]
62+
) -> None:
6163
"""Helper-function for async_update().
6264
Update the PW_Notification binary_sensor state.
6365
"""
@@ -66,7 +68,14 @@ def pw_notification_updater(devs, d_id, d_dict, notifs) -> None:
6668
devs[d_id]["binary_sensors"][item] = notifs != {}
6769

6870

69-
def update_helper(data, devs, d_dict, d_id, e_type, key) -> None:
71+
def update_helper(
72+
data: dict[str, Any],
73+
devs: dict[str, Any],
74+
d_dict: dict[str, Any],
75+
d_id: str,
76+
e_type: str,
77+
key: str,
78+
) -> None:
7079
"""Helper-function for async_update()."""
7180
for dummy in d_dict[e_type]:
7281
if key != dummy:
@@ -77,7 +86,7 @@ def update_helper(data, devs, d_dict, d_id, e_type, key) -> None:
7786
devs[d_id][e_type][item] = data[key]
7887

7988

80-
def check_model(name, v_name) -> str:
89+
def check_model(name: str, v_name: str) -> str:
8190
"""Model checking before using version_to_model."""
8291
if v_name in ["Plugwise", "Plugwise B.V."]:
8392
if name == "ThermoTouch":
@@ -89,7 +98,7 @@ def check_model(name, v_name) -> str:
8998
return name
9099

91100

92-
def schemas_schedule_temp(schedules, name) -> float | None:
101+
def schemas_schedule_temp(schedules: dict[str], name: str) -> float | None:
93102
"""Helper-function for schemas().
94103
Obtain the schedule temperature of the schema/schedule.
95104
"""
@@ -128,7 +137,7 @@ def schemas_schedule_temp(schedules, name) -> float | None:
128137
return schema_list[i][2]
129138

130139

131-
def types_finder(data) -> set:
140+
def types_finder(data: etree) -> set:
132141
"""Detect types within locations from logs."""
133142
types = set()
134143
for measure, attrs in HOME_MEASUREMENTS.items():
@@ -143,7 +152,9 @@ def types_finder(data) -> set:
143152
return types
144153

145154

146-
def power_data_local_format(attrs, key_string, val) -> float | int | bool:
155+
def power_data_local_format(
156+
attrs: dict[str, str], key_string: str, val: float | int
157+
) -> float | int | bool:
147158
"""Format power data."""
148159
f_val = format_measure(val, attrs[ATTR_UNIT_OF_MEASUREMENT])
149160
# Format only HOME_MEASUREMENT POWER_WATT values, do not move to util-format_meaure function!
@@ -156,7 +167,7 @@ def power_data_local_format(attrs, key_string, val) -> float | int | bool:
156167

157168

158169
def power_data_energy_diff(
159-
measurement, net_string, f_val, direct_data
170+
measurement: str, net_string: str, f_val: float | int, direct_data: dict[str, Any]
160171
) -> dict[str, Any]:
161172
"""Calculate differential energy."""
162173
if "electricity" in measurement and "interval" not in net_string:
@@ -180,12 +191,12 @@ class SmileComm:
180191

181192
def __init__(
182193
self,
183-
host,
184-
password,
185-
username,
186-
port,
187-
timeout,
188-
websession,
194+
host: str,
195+
password: str,
196+
username: str,
197+
port: str,
198+
timeout: str,
199+
websession: ClientSession,
189200
):
190201
"""Set the constructor for this class."""
191202
if not websession:
@@ -209,7 +220,9 @@ async def _create_session() -> ClientSession:
209220
self._endpoint = f"http://{host}:{str(port)}"
210221
self._timeout = timeout
211222

212-
async def _request_validate(self, resp, method) -> etree:
223+
async def _request_validate(
224+
self, resp: ClientResponse | None, method: str
225+
) -> etree:
213226
"""Helper-function for _request(): validate the returned data."""
214227
# Command accepted gives empty body with status 202
215228
if resp.status == 202:
@@ -333,7 +346,7 @@ def _locations_legacy(self) -> None:
333346
"members": appliances,
334347
}
335348

336-
def _locations_specials(self, loc, location) -> Munch:
349+
def _locations_specials(self, loc: Munch, location: str) -> Munch:
337350
"""Helper-function for _all_locations().
338351
Correct location info in special cases.
339352
"""
@@ -394,7 +407,9 @@ def _all_locations(self) -> None:
394407

395408
return
396409

397-
def _get_module_data(self, appliance, locator, mod_type) -> list[str | None]:
410+
def _get_module_data(
411+
self, appliance: etree, locator: str, mod_type: str
412+
) -> list[str | None]:
398413
"""Helper-function for _energy_device_info_finder() and _appliance_info_finder().
399414
Collect requested info from MODULES.
400415
"""
@@ -412,7 +427,7 @@ def _get_module_data(self, appliance, locator, mod_type) -> list[str | None]:
412427
return [v_name, v_model, hw_version, fw_version]
413428
return [None, None, None, None]
414429

415-
def _energy_device_info_finder(self, appliance, appl) -> Munch:
430+
def _energy_device_info_finder(self, appliance: etree, appl: Munch) -> Munch:
416431
"""Helper-function for _appliance_info_finder().
417432
Collect energy device info (Circle, Plug, Stealth): firmware, model and vendor name.
418433
"""
@@ -438,7 +453,7 @@ def _energy_device_info_finder(self, appliance, appl) -> Munch:
438453
appl.fw = module_data[3]
439454
return appl
440455

441-
def _appliance_info_finder(self, appliance, appl) -> Munch:
456+
def _appliance_info_finder(self, appliance: etree, appl: Munch) -> Munch:
442457
"""Collect device info (Smile/Stretch, Thermostats, OpenTherm/On-Off): firmware, model and vendor name."""
443458
# Find gateway and heater_central devices
444459
if appl.pwclass == "gateway":
@@ -509,7 +524,7 @@ def _appliance_info_finder(self, appliance, appl) -> Munch:
509524
# Cornercase just return existing dict-object
510525
return appl # pragma: no cover
511526

512-
def _appliance_types_finder(self, appliance, appl) -> Munch:
527+
def _appliance_types_finder(self, appliance: etree, appl: Munch) -> Munch:
513528
"""Helper-function for _all_appliances() - determine type(s) per appliance."""
514529
# Appliance with location (i.e. a device)
515530
if appliance.find("location") is not None:
@@ -634,7 +649,7 @@ def _match_locations(self) -> dict[str, Any]:
634649

635650
return matched_locations
636651

637-
def _control_state(self, loc_id) -> str | None:
652+
def _control_state(self, loc_id: str) -> str | None:
638653
"""Helper-function for _device_data_climate().
639654
Adam: find the thermostat control_state of a location, from DOMAIN_OBJECTS.
640655
Represents the heating/cooling demand-state of the local master thermostat.
@@ -694,7 +709,7 @@ def _presets(self, loc_id: str) -> dict[str, Any]:
694709

695710
return presets
696711

697-
def _rule_ids_by_name(self, name, loc_id) -> dict[str]:
712+
def _rule_ids_by_name(self, name: str, loc_id: str) -> dict[str]:
698713
"""Helper-function for _presets().
699714
Obtain the rule_id from the given name and and provide the location_id, when present.
700715
"""
@@ -708,7 +723,7 @@ def _rule_ids_by_name(self, name, loc_id) -> dict[str]:
708723

709724
return schema_ids
710725

711-
def _rule_ids_by_tag(self, tag, loc_id) -> dict[str]:
726+
def _rule_ids_by_tag(self, tag: str, loc_id: str) -> dict[str]:
712727
"""Helper-function for _presets(), _schemas() and _last_active_schema().
713728
Obtain the rule_id from the given template_tag and provide the location_id, when present.
714729
"""
@@ -724,7 +739,9 @@ def _rule_ids_by_tag(self, tag, loc_id) -> dict[str]:
724739

725740
return schema_ids
726741

727-
def _appliance_measurements(self, appliance, data, measurements) -> dict[str, Any]:
742+
def _appliance_measurements(
743+
self, appliance: etree, data: dict[str, Any], measurements: dict[str, Any]
744+
) -> dict[str, Any]:
728745
"""Helper-function for _get_appliance_data() - collect appliance measurement data."""
729746
for measurement, attrs in measurements:
730747
p_locator = f'.//logs/point_log[type="{measurement}"]/period/measurement'
@@ -762,7 +779,7 @@ def _appliance_measurements(self, appliance, data, measurements) -> dict[str, An
762779

763780
return data
764781

765-
def _get_appliance_data(self, d_id) -> dict[str, Any]:
782+
def _get_appliance_data(self, d_id: str) -> dict[str, Any]:
766783
"""Helper-function for smile.py: _get_device_data().
767784
Collect the appliance-data based on device id.
768785
Determined from APPLIANCES, for legacy from DOMAIN_OBJECTS.
@@ -813,7 +830,11 @@ def _get_appliance_data(self, d_id) -> dict[str, Any]:
813830
return data
814831

815832
def _rank_thermostat(
816-
self, thermo_matching, loc_id, appliance_id, appliance_details
833+
self,
834+
thermo_matching: dict[str, int],
835+
loc_id: str,
836+
appliance_id: str,
837+
appliance_details: dict[str, Any],
817838
) -> str:
818839
"""Helper-function for _scan_thermostats().
819840
Rank the thermostat based on appliance_details: master or slave."""
@@ -888,7 +909,7 @@ def _temperature_uri_legacy(self) -> str:
888909

889910
return f"{APPLIANCES};id={appliance_id}/thermostat"
890911

891-
def _temperature_uri(self, loc_id) -> str:
912+
def _temperature_uri(self, loc_id: str) -> str:
892913
"""Helper-function for smile.py: set_temperature().
893914
Determine the location-set_temperature uri - from LOCATIONS."""
894915
if self._smile_legacy:
@@ -964,7 +985,7 @@ def _heating_valves(self) -> int | None:
964985

965986
return None if loc_found == 0 else open_valve_count
966987

967-
def _power_data_peak_value(self, loc) -> Munch:
988+
def _power_data_peak_value(self, loc: str) -> Munch:
968989
"""Helper-function for _power_data_from_location()."""
969990
loc.found = True
970991
no_tariffs = False
@@ -1001,7 +1022,7 @@ def _power_data_peak_value(self, loc) -> Munch:
10011022

10021023
return loc
10031024

1004-
def _power_data_from_location(self, loc_id) -> dict[str, Any] | None:
1025+
def _power_data_from_location(self, loc_id: str) -> dict[str, Any] | None:
10051026
"""Helper-function for smile.py: _get_device_data().
10061027
Collect the power-data based on Location ID.
10071028
"""
@@ -1038,7 +1059,7 @@ def _power_data_from_location(self, loc_id) -> dict[str, Any] | None:
10381059

10391060
return direct_data
10401061

1041-
def _preset(self, loc_id) -> str | None:
1062+
def _preset(self, loc_id: str) -> str | None:
10421063
"""Helper-function for smile.py: device_data_climate().
10431064
Collect the active preset based on Location ID.
10441065
"""
@@ -1055,7 +1076,9 @@ def _preset(self, loc_id) -> str | None:
10551076
if preset is not None:
10561077
return preset.text
10571078

1058-
def _schemas_legacy(self, avail, sched_temp, sel) -> tuple[str, ...]:
1079+
def _schemas_legacy(
1080+
self, avail: list[str], sched_temp: str, sel: str
1081+
) -> tuple[str, ...]:
10591082
"""Helper-function for _schemas().
10601083
Collect available schemas/schedules for the legacy thermostat.
10611084
"""
@@ -1139,7 +1162,7 @@ def _schemas(self, location: str) -> tuple[str, ...]:
11391162

11401163
return available, selected, schedule_temperature, last_used
11411164

1142-
def _last_used_schedule(self, loc_id, rule_ids) -> str | None:
1165+
def _last_used_schedule(self, loc_id: str, rule_ids: dict[str]) -> str | None:
11431166
"""Helper-function for smile.py: _device_data_climate().
11441167
Determine the last-used schedule based on the location or the modified date.
11451168
"""
@@ -1168,7 +1191,7 @@ def _last_used_schedule(self, loc_id, rule_ids) -> str | None:
11681191

11691192
return last_used
11701193

1171-
def _object_value(self, obj_id, measurement) -> float | int | None:
1194+
def _object_value(self, obj_id: str, measurement: str) -> float | int | bool | None:
11721195
"""Helper-function for smile.py: _get_device_data() and _device_data_anna().
11731196
Obtain the value/state for the given object.
11741197
"""
@@ -1184,7 +1207,7 @@ def _object_value(self, obj_id, measurement) -> float | int | None:
11841207

11851208
return val
11861209

1187-
def _get_lock_state(self, xml) -> dict[str, Any]:
1210+
def _get_lock_state(self, xml: str) -> dict[str, Any]:
11881211
"""Helper-function for _get_appliance_data().
11891212
Adam & Stretches: obtain the relay-switch lock state.
11901213
"""
@@ -1203,7 +1226,13 @@ def _get_lock_state(self, xml) -> dict[str, Any]:
12031226

12041227
return data
12051228

1206-
def _create_dicts_from_data(self, data, bs_dict, s_dict, sw_dict) -> None:
1229+
def _create_dicts_from_data(
1230+
self,
1231+
data: dict[str, Any],
1232+
bs_dict: dict[str, bool],
1233+
s_dict: dict[str, Any],
1234+
sw_dict: dict[str, bool],
1235+
) -> None:
12071236
"""Helper-function for smile.py: _all_device_data().
12081237
Create dicts of binary_sensors, sensors, switches from the relevant data.
12091238
"""

0 commit comments

Comments
 (0)