1919 DEFAULT_TIMEOUT ,
2020 DEFAULT_USERNAME ,
2121 DOMAIN_OBJECTS ,
22+ LEGACY_SMILES ,
2223 LOCATIONS ,
2324 LOGGER ,
2425 MAX_SETPOINT ,
@@ -53,13 +54,7 @@ class SmileData(SmileHelper):
5354
5455 def update_for_cooling (self , devices : dict [str , DeviceData ]) -> None :
5556 """Helper-function for adding/updating various cooling-related values."""
56- for _ , device in devices .items ():
57- # For Anna or Adama + cooling, modify cooling_state based on provided info by Plugwise
58- if device ["dev_class" ] == "heater_central" and self ._cooling_present :
59- device ["binary_sensors" ]["cooling_state" ] = False
60- if self ._cooling_active :
61- device ["binary_sensors" ]["cooling_state" ] = True
62-
57+ for device in list (devices .values ()):
6358 # For Adam + on/off cooling, modify heating_state and cooling_state
6459 # based on provided info by Plugwise
6560 if (
@@ -76,8 +71,8 @@ def update_for_cooling(self, devices: dict[str, DeviceData]) -> None:
7671 if device ["dev_class" ] not in ZONE_THERMOSTATS :
7772 continue
7873
74+ # For heating + cooling, replace setpoint with setpoint_high/_low
7975 if self ._cooling_present :
80- # Replace setpoint with setpoint_high/_low
8176 thermostat = device ["thermostat" ]
8277 sensors = device ["sensors" ]
8378 max_setpoint = MAX_SETPOINT
@@ -152,7 +147,7 @@ def get_all_devices(self) -> None:
152147 self ._cooling_present = False
153148 if search .find (locator_1 ) is not None :
154149 self ._cooling_present = True
155- # Alternative method for the Anna with Elga, or alternative method for the Anna with Loria/Thermastage
150+ # Alternative method for the Anna with Elga
156151 elif search .find (locator_2 ) is not None :
157152 self ._cooling_present = True
158153
@@ -188,11 +183,14 @@ def _device_data_adam(
188183 """Helper-function for _get_device_data().
189184 Determine Adam device data.
190185 """
191- if self .smile_name == "Adam" :
192- # Indicate heating_state based on valves being open in case of city-provided heating
193- if details .get ("dev_class" ) == "heater_central" :
194- if self ._on_off_device and self ._heating_valves () is not None :
195- device_data ["heating_state" ] = self ._heating_valves () != 0
186+ # Indicate heating_state based on valves being open in case of city-provided heating
187+ if (
188+ self .smile_name == "Adam"
189+ and details .get ("dev_class" ) == "heater_central"
190+ and self ._on_off_device
191+ and self ._heating_valves () is not None
192+ ):
193+ device_data ["heating_state" ] = self ._heating_valves () != 0
196194
197195 return device_data
198196
@@ -210,7 +208,6 @@ def _device_data_climate(
210208 if presets := self ._presets (loc_id ):
211209 presets_list = list (presets )
212210 device_data ["preset_modes" ] = presets_list
213-
214211 device_data ["active_preset" ] = self ._preset (loc_id )
215212
216213 # Schedule
@@ -258,16 +255,16 @@ def _check_availability(
258255 # OpenTherm device
259256 if details ["dev_class" ] == "heater_central" and details ["name" ] != "OnOff" :
260257 device_data ["available" ] = True
261- for _ , data in self ._notifications .items ( ):
262- for _ , msg in data .items ( ):
258+ for data in list ( self ._notifications .values () ):
259+ for msg in list ( data .values () ):
263260 if "no OpenTherm communication" in msg :
264261 device_data ["available" ] = False
265262
266263 # Smartmeter
267264 if details ["dev_class" ] == "smartmeter" :
268265 device_data ["available" ] = True
269- for _ , data in self ._notifications .items ( ):
270- for _ , msg in data .items ( ):
266+ for data in list ( self ._notifications .values () ):
267+ for msg in list ( data .values () ):
271268 if "P1 does not seem to be connected to a smart meter" in msg :
272269 device_data ["available" ] = False
273270
@@ -299,31 +296,30 @@ def _get_device_data(self, dev_id: str) -> DeviceData:
299296 device_data .pop ("thermostat" )
300297
301298 # Generic
302- if details ["dev_class" ] == "gateway" or dev_id == self .gateway_id :
303- if self .smile_type == "thermostat" :
304- # Adam & Anna: the Smile outdoor_temperature is present in DOMAIN_OBJECTS and LOCATIONS - under Home
305- # The outdoor_temperature present in APPLIANCES is a local sensor connected to the active device
306- outdoor_temperature = self ._object_value (
307- self ._home_location , "outdoor_temperature"
308- )
309- if outdoor_temperature is not None :
310- device_data ["outdoor_temperature" ] = outdoor_temperature
299+ if self .smile_type == "thermostat" and details ["dev_class" ] == "gateway" :
300+ # Adam & Anna: the Smile outdoor_temperature is present in DOMAIN_OBJECTS and LOCATIONS - under Home
301+ # The outdoor_temperature present in APPLIANCES is a local sensor connected to the active device
302+ outdoor_temperature = self ._object_value (
303+ self ._home_location , "outdoor_temperature"
304+ )
305+ if outdoor_temperature is not None :
306+ device_data ["outdoor_temperature" ] = outdoor_temperature
311307
312- # Show the allowed regulation modes
313- if self ._reg_allowed_modes :
314- device_data ["regulation_modes" ] = self ._reg_allowed_modes
308+ # Show the allowed regulation modes
309+ if self ._reg_allowed_modes :
310+ device_data ["regulation_modes" ] = self ._reg_allowed_modes
315311
316312 # Show the allowed dhw_modes
317- if details ["dev_class" ] == "heater_central" :
318- if self ._dhw_allowed_modes :
319- device_data ["dhw_modes" ] = self ._dhw_allowed_modes
313+ if details ["dev_class" ] == "heater_central" and self ._dhw_allowed_modes :
314+ device_data ["dhw_modes" ] = self ._dhw_allowed_modes
320315
321- if details ["dev_class" ] == "smartmeter" :
322- # Get P1 data from LOCATIONS
323- if (
324- power_data := self ._power_data_from_location (details ["location" ])
325- ) is not None :
326- device_data .update (power_data )
316+ # Get P1 data from LOCATIONS
317+ if (
318+ details ["dev_class" ] == "smartmeter"
319+ and (power_data := self ._power_data_from_location (details ["location" ]))
320+ is not None
321+ ):
322+ device_data .update (power_data )
327323
328324 # Check availability of non-legacy wired-connected devices
329325 if not self ._smile_legacy :
@@ -388,14 +384,13 @@ async def connect(self) -> bool:
388384 models .append (model .text )
389385
390386 dsmrmain = result .find ("./module/protocols/dsmrmain" )
391- if "Plugwise" not in names :
392- if dsmrmain is None : # pragma: no cover
393- LOGGER .error (
394- "Connected but expected text not returned, we got %s. Please create \
395- an issue on http://github.com/plugwise/python-plugwise" ,
396- result ,
397- )
398- raise ResponseError
387+ if "Plugwise" not in names and dsmrmain is None : # pragma: no cover
388+ LOGGER .error (
389+ "Connected but expected text not returned, we got %s. Please create \
390+ an issue on http://github.com/plugwise/python-plugwise" ,
391+ result ,
392+ )
393+ raise ResponseError
399394
400395 # Check if Anna is connected to an Adam
401396 if "159.2" in models :
@@ -499,7 +494,7 @@ async def _smile_detect(self, result: etree, dsmrmain: etree) -> None:
499494 self .smile_type = SMILES [target_smile ].smile_type
500495 self .smile_version = (self .smile_fw_version , ver )
501496
502- if target_smile in ( "smile_thermo_v1" , "smile_v2" , "stretch_v3" , "stretch_v2" ) :
497+ if target_smile in LEGACY_SMILES :
503498 self ._smile_legacy = True
504499
505500 if self .smile_type == "stretch" :
0 commit comments