Skip to content

Commit 04b889d

Browse files
committed
Update helper.py
1 parent 7e2e4c2 commit 04b889d

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

plugwise/helper.py

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import asyncio
88
import datetime as dt
9-
from typing import Any, cast
109

1110
# This way of importing aiohttp is because of patch/mocking in testing (aiohttp timeouts)
1211
from aiohttp import BasicAuth, ClientError, ClientResponse, ClientSession, ClientTimeout
@@ -50,9 +49,9 @@
5049
THERMOSTAT_CLASSES,
5150
TOGGLES,
5251
UOM,
52+
ActuatorData,
5353
ApplianceData,
5454
DeviceData,
55-
DeviceDataPoints,
5655
GatewayData,
5756
ModelData,
5857
SmileBinarySensors,
@@ -73,9 +72,11 @@
7372
version_to_model,
7473
)
7574

75+
# from typing import cast
76+
7677

7778
def update_helper(
78-
data: DeviceDataPoints,
79+
data: DeviceData,
7980
devices: dict[str, DeviceData],
8081
device_dict: DeviceData,
8182
device_id: str,
@@ -103,20 +104,20 @@ def check_model(name: str | None, vendor_name: str | None) -> str | None:
103104
return name
104105

105106

106-
def _get_actuator_functionalities(xml: etree, data: dict[str, Any]) -> None:
107+
def _get_actuator_functionalities(xml: etree, data: DeviceData) -> None:
107108
"""Helper-function for _get_appliance_data()."""
108109
for item in ACTIVE_ACTUATORS:
109-
temp_dict: dict[str, float] = {}
110+
temp_dict: ActuatorData = {}
110111
for key in LIMITS:
111112
locator = f'.//actuator_functionalities/thermostat_functionality[type="{item}"]/{key}'
112113
if (function := xml.find(locator)) is not None:
113114
if function.text == "nil":
114115
break
115116

116-
temp_dict.update({key: format_measure(function.text, TEMP_CELSIUS)})
117+
temp_dict[key] = format_measure(function.text, TEMP_CELSIUS) # type: ignore [literal-required]
117118

118119
if temp_dict:
119-
data[item] = temp_dict
120+
data[item] = temp_dict # type: ignore [literal-required]
120121

121122

122123
def schedules_temps(
@@ -438,12 +439,12 @@ def _get_module_data(
438439
"""
439440
model_data: ModelData = {
440441
"contents": False,
442+
"firmware_version": None,
443+
"hardware_version": None,
444+
"reachable": None,
441445
"vendor_name": None,
442446
"vendor_model": None,
443-
"hardware_version": None,
444-
"firmware_version": None,
445447
"zigbee_mac_address": None,
446-
"available": None,
447448
}
448449
if (appl_search := appliance.find(locator)) is not None:
449450
link_id = appl_search.attrib["id"]
@@ -461,7 +462,7 @@ def _get_module_data(
461462
# Adam
462463
if found := module.find("./protocols/zig_bee_node"):
463464
model_data["zigbee_mac_address"] = found.find("mac_address").text
464-
model_data["available"] = found.find("reachable").text == "true"
465+
model_data["reachable"] = found.find("reachable").text == "true"
465466
# Stretches
466467
if found := module.find("./protocols/network_router"):
467468
model_data["zigbee_mac_address"] = found.find("mac_address").text
@@ -860,7 +861,7 @@ def _rule_ids_by_tag(self, tag: str, loc_id: str) -> dict[str, str]:
860861
def _appliance_measurements(
861862
self,
862863
appliance: etree,
863-
data: dict[str, Any],
864+
data: DeviceData,
864865
measurements: dict[str, DATA | UOM],
865866
) -> None:
866867
"""Helper-function for _get_appliance_data() - collect appliance measurement data."""
@@ -881,28 +882,28 @@ def _appliance_measurements(
881882
if new_name := getattr(attrs, ATTR_NAME, None):
882883
measurement = new_name
883884

884-
data[measurement] = appl_p_loc.text
885+
data[measurement] = appl_p_loc.text # type: ignore [literal-required]
885886
# measurements with states "on" or "off" that need to be passed directly
886887
if measurement not in ("dhw_mode"):
887-
data[measurement] = format_measure(
888+
data[measurement] = format_measure( # type: ignore [literal-required]
888889
appl_p_loc.text, getattr(attrs, ATTR_UNIT_OF_MEASUREMENT)
889890
)
890891

891892
# Anna: save cooling-related measurements for later use
892893
# Use the local outdoor temperature as reference for turning cooling on/off
893894
if measurement == "cooling_activation_outdoor_temperature":
894-
self._cooling_activation_outdoor_temp = data[measurement]
895+
self._cooling_activation_outdoor_temp = data[measurement] # type: ignore [literal-required]
895896
if measurement == "cooling_deactivation_threshold":
896-
self._cooling_deactivation_threshold = data[measurement]
897+
self._cooling_deactivation_threshold = data[measurement] # type: ignore [literal-required]
897898
if measurement == "outdoor_air_temperature":
898-
self._outdoor_temp = data[measurement]
899+
self._outdoor_temp = data[measurement] # type: ignore [literal-required]
899900

900901
i_locator = f'.//logs/interval_log[type="{measurement}"]/period/measurement'
901902
if (appl_i_loc := appliance.find(i_locator)) is not None:
902903
name = f"{measurement}_interval"
903-
data[name] = format_measure(appl_i_loc.text, ENERGY_WATT_HOUR)
904+
data[name] = format_measure(appl_i_loc.text, ENERGY_WATT_HOUR) # type: ignore [literal-required]
904905

905-
def _wireless_availablity(self, appliance: etree, data: dict[str, Any]) -> None:
906+
def _wireless_availablity(self, appliance: etree, data: DeviceData) -> None:
906907
"""Helper-function for _get_appliance_data().
907908
908909
Collect the availablity-status for wireless connected devices.
@@ -912,16 +913,16 @@ def _wireless_availablity(self, appliance: etree, data: dict[str, Any]) -> None:
912913
locator = "./logs/interval_log/electricity_interval_meter"
913914
mod_type = "electricity_interval_meter"
914915
module_data = self._get_module_data(appliance, locator, mod_type)
915-
if module_data["available"] is None:
916+
if module_data["reachable"] is None:
916917
# Collect for wireless thermostats
917918
locator = "./logs/point_log[type='thermostat']/thermostat"
918919
mod_type = "thermostat"
919920
module_data = self._get_module_data(appliance, locator, mod_type)
920921

921-
if module_data["available"] is not None:
922-
data["available"] = module_data["available"]
922+
if module_data["reachable"] is not None:
923+
data["available"] = module_data["reachable"]
923924

924-
def _get_regulation_mode(self, appliance: etree, data: dict[str, Any]) -> None:
925+
def _get_regulation_mode(self, appliance: etree, data: DeviceData) -> None:
925926
"""Helper-function for _get_appliance_data().
926927
927928
Collect the gateway regulation_mode.
@@ -931,7 +932,7 @@ def _get_regulation_mode(self, appliance: etree, data: dict[str, Any]) -> None:
931932
data["regulation_mode"] = search.find("mode").text
932933
self._cooling_enabled = search.find("mode").text == "cooling"
933934

934-
def _cleanup_data(self, data: dict[str, Any]) -> None:
935+
def _cleanup_data(self, data: DeviceData) -> None:
935936
"""Helper-function for _get_appliance_data().
936937
937938
Clean up the data dict.
@@ -949,7 +950,7 @@ def _cleanup_data(self, data: dict[str, Any]) -> None:
949950
if not self._elga and "cooling_enabled" in data:
950951
data.pop("cooling_enabled") # pragma: no cover
951952

952-
def _process_c_heating_state(self, data: dict[str, Any]) -> None:
953+
def _process_c_heating_state(self, data: DeviceData) -> None:
953954
"""Helper-function for _get_appliance_data().
954955
955956
Process the central_heating_state value.
@@ -978,10 +979,10 @@ def _get_appliance_data(self, d_id: str) -> DeviceData:
978979
Collect the appliance-data based on device id.
979980
Determined from APPLIANCES, for legacy from DOMAIN_OBJECTS.
980981
"""
981-
data: dict[str, Any] = {}
982+
data: DeviceData = {}
982983
# P1 legacy has no APPLIANCES, also not present in DOMAIN_OBJECTS
983984
if self._smile_legacy and self.smile_type == "power":
984-
return cast(DeviceData, data)
985+
return data
985986

986987
measurements = DEVICE_MEASUREMENTS
987988
if d_id == self._heater_id:
@@ -1036,7 +1037,7 @@ def _get_appliance_data(self, d_id: str) -> DeviceData:
10361037

10371038
self._cleanup_data(data)
10381039

1039-
return cast(DeviceData, data)
1040+
return data
10401041

10411042
def _rank_thermostat(
10421043
self,
@@ -1453,7 +1454,7 @@ def _object_value(self, obj_id: str, measurement: str) -> float | int | None:
14531454

14541455
return val
14551456

1456-
def _get_lock_state(self, xml: etree, data: dict[str, Any]) -> None:
1457+
def _get_lock_state(self, xml: etree, data: DeviceData) -> None:
14571458
"""Helper-function for _get_appliance_data().
14581459
14591460
Adam & Stretches: obtain the relay-switch lock state.
@@ -1469,7 +1470,7 @@ def _get_lock_state(self, xml: etree, data: dict[str, Any]) -> None:
14691470
data["lock"] = found.text == "true"
14701471

14711472
def _get_toggle_state(
1472-
self, xml: etree, toggle: str, name: str, data: dict[str, Any]
1473+
self, xml: etree, toggle: str, name: str, data: DeviceData
14731474
) -> None:
14741475
"""Helper-function for _get_appliance_data().
14751476
@@ -1481,7 +1482,7 @@ def _get_toggle_state(
14811482
for item in found:
14821483
if (toggle_type := item.find("type")) is not None:
14831484
if toggle_type.text == toggle:
1484-
data.update({name: item.find("state").text == "on"})
1485+
data[name] = item.find("state").text == "on" # type: ignore [literal-required]
14851486
# Remove the cooling_enabled key when the corresponding toggle is present
14861487
# Except for Elga
14871488
if toggle == "cooling_enabled" and not self._elga:

0 commit comments

Comments
 (0)