@@ -72,13 +72,13 @@ def _update_gw_devices(self) -> None:
7272 """
7373 for device_id , device in self .gw_devices .items ():
7474 data = self ._get_device_data (device_id )
75- self ._add_or_update_notifications (data , device_id , device )
75+ self ._add_or_update_notifications (device_id , device , data )
7676 device .update (data )
7777 self ._update_for_cooling (device )
7878 remove_empty_platform_dicts (device )
7979
8080 def _add_or_update_notifications (
81- self , data : DeviceData , device_id : str , device : DeviceData
81+ self , device_id : str , device : DeviceData , data : DeviceData
8282 ) -> None :
8383 """Helper-function adding or updating the Plugwise notifications."""
8484 if (
@@ -169,99 +169,83 @@ def _all_device_data(self) -> None:
169169 )
170170
171171 def _device_data_switching_group (
172- self , device : DeviceData , device_data : DeviceData
173- ) -> DeviceData :
172+ self , device : DeviceData , data : DeviceData
173+ ) -> None :
174174 """Helper-function for _get_device_data().
175175
176176 Determine switching group device data.
177177 """
178- if device ["dev_class" ] not in SWITCH_GROUP_TYPES :
179- return device_data
180-
181- counter = 0
182- for member in device ["members" ]:
183- if self .gw_devices [member ]["switches" ].get ("relay" ):
184- counter += 1
185- device_data ["switches" ]["relay" ] = counter != 0
186- self ._count += 1
187- return device_data
178+ if device ["dev_class" ] in SWITCH_GROUP_TYPES :
179+ counter = 0
180+ for member in device ["members" ]:
181+ if self .gw_devices [member ]["switches" ].get ("relay" ):
182+ counter += 1
183+ data ["switches" ]["relay" ] = counter != 0
184+ self ._count += 1
188185
189- def _device_data_adam (
190- self , device : DeviceData , device_data : DeviceData
191- ) -> DeviceData :
186+ def _device_data_adam (self , device : DeviceData , data : DeviceData ) -> None :
192187 """Helper-function for _get_device_data().
193188
194189 Determine Adam heating-status for on-off heating via valves,
195190 available regulations_modes and thermostat control_states.
196191 """
197- if not self .smile (ADAM ):
198- return device_data
199-
200- # Indicate heating_state based on valves being open in case of city-provided heating
201- if (
202- device ["dev_class" ] == "heater_central"
203- and self ._on_off_device
204- and isinstance (self ._heating_valves (), int )
205- ):
206- device_data ["binary_sensors" ]["heating_state" ] = self ._heating_valves () != 0
207-
208- # Show the allowed regulation modes for Adam
209- if device ["dev_class" ] == "gateway" and self ._reg_allowed_modes :
210- device_data ["regulation_modes" ] = self ._reg_allowed_modes
211- self ._count += 1
212-
213- # Control_state, only for Adam master thermostats
214- if device ["dev_class" ] in ZONE_THERMOSTATS :
215- loc_id = device ["location" ]
216- if ctrl_state := self ._control_state (loc_id ):
217- device_data ["control_state" ] = ctrl_state
192+ if self .smile (ADAM ):
193+ # Indicate heating_state based on valves being open in case of city-provided heating
194+ if (
195+ device ["dev_class" ] == "heater_central"
196+ and self ._on_off_device
197+ and isinstance (self ._heating_valves (), int )
198+ ):
199+ data ["binary_sensors" ]["heating_state" ] = self ._heating_valves () != 0
200+
201+ # Show the allowed regulation modes for Adam
202+ if device ["dev_class" ] == "gateway" and self ._reg_allowed_modes :
203+ data ["regulation_modes" ] = self ._reg_allowed_modes
218204 self ._count += 1
219205
220- return device_data
206+ # Control_state, only for Adam master thermostats
207+ if device ["dev_class" ] in ZONE_THERMOSTATS :
208+ loc_id = device ["location" ]
209+ if ctrl_state := self ._control_state (loc_id ):
210+ data ["control_state" ] = ctrl_state
211+ self ._count += 1
221212
222- def _device_data_climate (
223- self , device : DeviceData , device_data : DeviceData
224- ) -> DeviceData :
213+ def _device_data_climate (self , device : DeviceData , data : DeviceData ) -> None :
225214 """Helper-function for _get_device_data().
226215
227216 Determine climate-control device data.
228217 """
229218 loc_id = device ["location" ]
230219
231220 # Presets
232- device_data ["preset_modes" ] = None
233- device_data ["active_preset" ] = None
221+ data ["preset_modes" ] = None
222+ data ["active_preset" ] = None
234223 self ._count += 2
235224 if presets := self ._presets (loc_id ):
236- device_data ["preset_modes" ] = list (presets )
237- device_data ["active_preset" ] = self ._preset (loc_id )
225+ data ["preset_modes" ] = list (presets )
226+ data ["active_preset" ] = self ._preset (loc_id )
238227
239228 # Schedule
240229 avail_schedules , sel_schedule = self ._schedules (loc_id )
241- device_data ["available_schedules" ] = avail_schedules
242- device_data ["select_schedule" ] = sel_schedule
230+ data ["available_schedules" ] = avail_schedules
231+ data ["select_schedule" ] = sel_schedule
243232 self ._count += 2
244233
245234 # Operation modes: auto, heat, heat_cool, cool and off
246- device_data ["mode" ] = "auto"
235+ data ["mode" ] = "auto"
247236 self ._count += 1
248237 if sel_schedule == NONE :
249- device_data ["mode" ] = "heat"
238+ data ["mode" ] = "heat"
250239 if self ._cooling_present :
251- device_data ["mode" ] = (
252- "cool" if self .check_reg_mode ("cooling" ) else "heat_cool"
253- )
240+ data ["mode" ] = "cool" if self .check_reg_mode ("cooling" ) else "heat_cool"
254241
255242 if self .check_reg_mode ("off" ):
256- device_data ["mode" ] = "off"
257-
258- if NONE in avail_schedules :
259- return device_data
243+ data ["mode" ] = "off"
260244
261- self . _get_schedule_states_with_off (
262- loc_id , avail_schedules , sel_schedule , device_data
263- )
264- return device_data
245+ if NONE not in avail_schedules :
246+ self . _get_schedule_states_with_off (
247+ loc_id , avail_schedules , sel_schedule , data
248+ )
265249
266250 def check_reg_mode (self , mode : str ) -> bool :
267251 """Helper-function for device_data_climate()."""
@@ -293,53 +277,53 @@ def _get_schedule_states_with_off(
293277 if all_off :
294278 data ["select_schedule" ] = OFF
295279
296- def _check_availability (self , device : DeviceData , device_data : DeviceData ) -> None :
280+ def _check_availability (
281+ self , device : DeviceData , dev_class : str , data : DeviceData , message : str
282+ ) -> None :
297283 """Helper-function for _get_device_data().
298284
299285 Provide availability status for the wired-commected devices.
300286 """
301- # OpenTherm device
302- if device ["dev_class" ] == "heater_central" and device ["name" ] != "OnOff" :
303- device_data ["available" ] = True
304- self ._count += 1
305- for data in self ._notifications .values ():
306- for msg in data .values ():
307- if "no OpenTherm communication" in msg :
308- device_data ["available" ] = False
309-
310- # Smartmeter
311- if device ["dev_class" ] == "smartmeter" :
312- device_data ["available" ] = True
287+ if device ["dev_class" ] == dev_class :
288+ data ["available" ] = True
313289 self ._count += 1
314- for data in self ._notifications .values ():
315- for msg in data .values ():
316- if "P1 does not seem to be connected to a smart meter" in msg :
317- device_data ["available" ] = False
290+ for item in self ._notifications .values ():
291+ for msg in item .values ():
292+ if message in msg :
293+ data ["available" ] = False
318294
319295 def _get_device_data (self , dev_id : str ) -> DeviceData :
320296 """Helper-function for _all_device_data() and async_update().
321297
322298 Provide device-data, based on Location ID (= dev_id), from APPLIANCES.
323299 """
324300 device = self .gw_devices [dev_id ]
325- device_data = self ._get_measurement_data (dev_id )
301+ data = self ._get_measurement_data (dev_id )
326302
327303 # Check availability of non-legacy wired-connected devices
328304 if not self ._smile_legacy :
329- self ._check_availability (device , device_data )
305+ # Smartmeter
306+ self ._check_availability (
307+ device , "smartmeter" , data , "P1 does not seem to be connected"
308+ )
309+ # OpenTherm device
310+ if device ["name" ] != "OnOff" :
311+ self ._check_availability (
312+ device , "heater_central" , data , "no OpenTherm communication"
313+ )
330314
331315 # Switching groups data
332- device_data = self ._device_data_switching_group (device , device_data )
316+ self ._device_data_switching_group (device , data )
333317 # Adam data
334- device_data = self ._device_data_adam (device , device_data )
318+ self ._device_data_adam (device , data )
335319 # Skip obtaining data for non master-thermostats
336320 if device ["dev_class" ] not in ZONE_THERMOSTATS :
337- return device_data
321+ return data
338322
339323 # Thermostat data (presets, temperatures etc)
340- device_data = self ._device_data_climate (device , device_data )
324+ self ._device_data_climate (device , data )
341325
342- return device_data
326+ return data
343327
344328
345329class Smile (SmileComm , SmileData ):
0 commit comments