55
66import asyncio
77import datetime as dt
8+ from typing import Any , cast
89
910# This way of importing aiohttp is because of patch/mocking in testing (aiohttp timeouts)
1011from aiohttp import BasicAuth , ClientError , ClientResponse , ClientSession , ClientTimeout
@@ -100,9 +101,9 @@ def check_model(name: str | None, vendor_name: str | None) -> str | None:
100101 return name
101102
102103
103- def _get_actuator_functionalities (xml : etree ) -> DeviceData :
104+ def _get_actuator_functionalities (xml : etree ) -> dict [ str , Any ] :
104105 """Helper-function for _get_appliance_data()."""
105- data : DeviceData = {}
106+ data : dict [ str , Any ] = {}
106107 for item in ACTIVE_ACTUATORS :
107108 temp_dict : dict [str , float ] = {}
108109 for key in LIMITS :
@@ -114,7 +115,7 @@ def _get_actuator_functionalities(xml: etree) -> DeviceData:
114115 temp_dict .update ({key : format_measure (function .text , TEMP_CELSIUS )})
115116
116117 if temp_dict :
117- data [item ] = temp_dict # type: ignore [literal-required]
118+ data [item ] = temp_dict
118119
119120 return data
120121
@@ -849,9 +850,9 @@ def _rule_ids_by_tag(self, tag: str, loc_id: str) -> dict[str, str]:
849850 def _appliance_measurements (
850851 self ,
851852 appliance : etree ,
852- data : DeviceData ,
853+ data : dict [ str , Any ] ,
853854 measurements : dict [str , DATA | UOM ],
854- ) -> DeviceData :
855+ ) -> None :
855856 """Helper-function for _get_appliance_data() - collect appliance measurement data."""
856857 for measurement , attrs in measurements .items ():
857858 p_locator = f'.//logs/point_log[type="{ measurement } "]/period/measurement'
@@ -870,28 +871,28 @@ def _appliance_measurements(
870871 if new_name := getattr (attrs , ATTR_NAME , None ):
871872 measurement = new_name
872873
873- data [measurement ] = appl_p_loc .text # type: ignore [literal-required]
874+ data [measurement ] = appl_p_loc .text
874875 # measurements with states "on" or "off" that need to be passed directly
875876 if measurement not in ["dhw_mode" , "regulation_mode" ]:
876- data [measurement ] = format_measure (appl_p_loc .text , getattr (attrs , ATTR_UNIT_OF_MEASUREMENT )) # type: ignore [literal-required]
877+ data [measurement ] = format_measure (
878+ appl_p_loc .text , getattr (attrs , ATTR_UNIT_OF_MEASUREMENT )
879+ )
877880
878881 # Anna: save cooling-related measurements for later use
879882 # Use the local outdoor temperature as reference for turning cooling on/off
880883 if measurement == "cooling_activation_outdoor_temperature" :
881- self ._cooling_activation_outdoor_temp = data [measurement ] # type: ignore [literal-required]
884+ self ._cooling_activation_outdoor_temp = data [measurement ]
882885 if measurement == "cooling_deactivation_threshold" :
883- self ._cooling_deactivation_threshold = data [measurement ] # type: ignore [literal-required]
886+ self ._cooling_deactivation_threshold = data [measurement ]
884887 if measurement == "outdoor_air_temperature" :
885- self ._outdoor_temp = data [measurement ] # type: ignore [literal-required]
888+ self ._outdoor_temp = data [measurement ]
886889
887890 i_locator = f'.//logs/interval_log[type="{ measurement } "]/period/measurement'
888891 if (appl_i_loc := appliance .find (i_locator )) is not None :
889892 name = f"{ measurement } _interval"
890- data [name ] = format_measure (appl_i_loc .text , ENERGY_WATT_HOUR ) # type: ignore [literal-required]
891-
892- return data
893+ data [name ] = format_measure (appl_i_loc .text , ENERGY_WATT_HOUR )
893894
894- def _wireless_availablity (self , appliance : etree , data : DeviceData ) -> None :
895+ def _wireless_availablity (self , appliance : etree , data : dict [ str , Any ] ) -> None :
895896 """Helper-function for _get_appliance_data().
896897 Collect the availablity-status for wireless connected devices.
897898 """
@@ -914,10 +915,10 @@ def _get_appliance_data(self, d_id: str) -> DeviceData:
914915 Collect the appliance-data based on device id.
915916 Determined from APPLIANCES, for legacy from DOMAIN_OBJECTS.
916917 """
917- data : DeviceData = {}
918+ data : dict [ str , Any ] = {}
918919 # P1 legacy has no APPLIANCES, also not present in DOMAIN_OBJECTS
919920 if self ._smile_legacy and self .smile_type == "power" :
920- return data
921+ return cast ( DeviceData , data )
921922
922923 measurements = DEVICE_MEASUREMENTS
923924 if d_id == self ._heater_id :
@@ -927,11 +928,10 @@ def _get_appliance_data(self, d_id: str) -> DeviceData:
927928 appliance := self ._appliances .find (f'./appliance[@id="{ d_id } "]' )
928929 ) is not None :
929930
930- data = self ._appliance_measurements (appliance , data , measurements )
931- data . update ( self ._get_lock_state (appliance ) )
931+ self ._appliance_measurements (appliance , data , measurements )
932+ self ._get_lock_state (appliance , data )
932933 for toggle , name in TOGGLES .items ():
933- if self ._get_toggle_state (appliance , toggle , name ) is not None :
934- data .update (self ._get_toggle_state (appliance , toggle , name ))
934+ self ._get_toggle_state (appliance , toggle , name , data )
935935
936936 if appliance .find ("type" ).text in ACTUATOR_CLASSES :
937937 data .update (_get_actuator_functionalities (appliance ))
@@ -988,7 +988,7 @@ def _get_appliance_data(self, d_id: str) -> DeviceData:
988988 if not self ._cooling_present and "cooling_state" in data :
989989 data .pop ("cooling_state" )
990990
991- return data
991+ return cast ( DeviceData , data )
992992
993993 def _rank_thermostat (
994994 self ,
@@ -1342,11 +1342,10 @@ def _object_value(self, obj_id: str, measurement: str) -> float | int | None:
13421342
13431343 return val
13441344
1345- def _get_lock_state (self , xml : etree ) -> DeviceData :
1345+ def _get_lock_state (self , xml : etree , data : dict [ str , Any ] ) -> None :
13461346 """Helper-function for _get_appliance_data().
13471347 Adam & Stretches: obtain the relay-switch lock state.
13481348 """
1349- data : DeviceData = {}
13501349 actuator = "actuator_functionalities"
13511350 func_type = "relay_functionality"
13521351 if self ._stretch_v2 :
@@ -1357,29 +1356,19 @@ def _get_lock_state(self, xml: etree) -> DeviceData:
13571356 if (found := xml .find (locator )) is not None :
13581357 data ["lock" ] = found .text == "true"
13591358
1360- return data
1361-
13621359 def _get_toggle_state (
1363- self , xml : etree , toggle : str , name : str
1364- ) -> DeviceData | None :
1360+ self , xml : etree , toggle : str , name : str , data : dict [ str , Any ]
1361+ ) -> None :
13651362 """Helper-function for _get_appliance_data().
13661363 Obtain the toggle state of 'toggle'.
13671364 """
1368- data : DeviceData = {}
13691365 if xml .find ("type" ).text == "heater_central" :
13701366 locator = "./actuator_functionalities/toggle_functionality"
1371- if not (found := xml .findall (locator )):
1372- return None
1373-
1374- for item in found :
1375- if (toggle_type := item .find ("type" )) is not None :
1376- if toggle_type .text == toggle :
1377- data .update ({name : item .find ("state" ).text == "on" })
1378-
1379- if data :
1380- return data
1381-
1382- return None
1367+ if found := xml .findall (locator ):
1368+ for item in found :
1369+ if (toggle_type := item .find ("type" )) is not None :
1370+ if toggle_type .text == toggle :
1371+ data .update ({name : item .find ("state" ).text == "on" })
13831372
13841373 def _update_device_with_dicts (
13851374 self ,
0 commit comments