@@ -55,12 +55,11 @@ def _update_gw_entities(self) -> None:
5555 """
5656 mac_list : list [str ] = []
5757 for entity_id , entity in self .gw_entities .items ():
58- data = self ._get_entity_data (entity_id )
58+ self ._get_entity_data (entity_id , entity )
5959 if entity_id == self ._gateway_id :
6060 mac_list = self ._detect_low_batteries ()
61- self ._add_or_update_notifications (entity_id , entity , data )
61+ self ._add_or_update_notifications (entity_id , entity )
6262
63- entity .update (data )
6463 is_battery_low = (
6564 mac_list
6665 and "low_battery" in entity ["binary_sensors" ]
@@ -106,7 +105,7 @@ def _detect_low_batteries(self) -> list[str]:
106105 return mac_address_list
107106
108107 def _add_or_update_notifications (
109- self , entity_id : str , entity : GwEntityData , data : GwEntityData
108+ self , entity_id : str , entity : GwEntityData
110109 ) -> None :
111110 """Helper-function adding or updating the Plugwise notifications."""
112111 if (
@@ -116,8 +115,8 @@ def _add_or_update_notifications(
116115 "binary_sensors" in entity
117116 and "plugwise_notification" in entity ["binary_sensors" ]
118117 ):
119- data ["binary_sensors" ]["plugwise_notification" ] = bool (self ._notifications )
120- data ["notifications" ] = self ._notifications
118+ entity ["binary_sensors" ]["plugwise_notification" ] = bool (self ._notifications )
119+ entity ["notifications" ] = self ._notifications
121120 self ._count += 2
122121
123122 def _update_for_cooling (self , entity : GwEntityData ) -> None :
@@ -177,59 +176,56 @@ def _get_location_data(self, loc_id: str) -> GwEntityData:
177176 self ._count -= 1
178177
179178 # Thermostat data (presets, temperatures etc)
180- self ._climate_data (loc_id , zone , data )
179+ self ._climate_data (loc_id , zone )
181180
182181 return data
183182
184- def _get_entity_data (self , entity_id : str ) -> GwEntityData :
183+ def _get_entity_data (self , entity_id : str , entity : GwEntityData ) -> None :
185184 """Helper-function for _update_gw_entities() and async_update().
186185
187186 Provide entity-data, based on appliance_id (= entity_id).
188187 """
189- entity = self .gw_entities [entity_id ]
190- data = self ._get_measurement_data (entity_id )
188+ self ._get_measurement_data (entity_id , entity )
191189
192190 # Check availability of wired-connected entities
193191 # Smartmeter
194192 self ._check_availability (
195- entity , "smartmeter" , data , "P1 does not seem to be connected"
193+ entity , "smartmeter" , "P1 does not seem to be connected"
196194 )
197195 # OpenTherm entity
198196 if entity ["name" ] != "OnOff" :
199197 self ._check_availability (
200- entity , "heater_central" , data , "no OpenTherm communication"
198+ entity , "heater_central" , "no OpenTherm communication"
201199 )
202200
203201 # Switching groups data
204- self ._entity_switching_group (entity , data )
202+ self ._entity_switching_group (entity )
205203 # Adam data
206204 if self .check_name (ADAM ):
207- self ._get_adam_data (entity , data )
205+ self ._get_adam_data (entity )
208206
209207 # Thermostat data for Anna (presets, temperatures etc)
210208 if self .check_name (ANNA ) and entity ["dev_class" ] == "thermostat" :
211- self ._climate_data (entity_id , entity , data )
212- self ._get_anna_control_state (data )
213-
214- return data
209+ self ._climate_data (entity_id , entity )
210+ self ._get_anna_control_state (entity )
215211
216212 def _check_availability (
217- self , entity : GwEntityData , dev_class : str , data : GwEntityData , message : str
213+ self , entity : GwEntityData , dev_class : str , message : str
218214 ) -> None :
219215 """Helper-function for _get_entity_data().
220216
221217 Provide availability status for the wired-connected devices.
222218 """
223219 if entity ["dev_class" ] == dev_class :
224- data ["available" ] = True
220+ entity ["available" ] = True
225221 self ._count += 1
226222 for item in self ._notifications .values ():
227223 for msg in item .values ():
228224 if message in msg :
229- data ["available" ] = False
225+ entity ["available" ] = False
230226 break
231227
232- def _get_adam_data (self , entity : GwEntityData , data : GwEntityData ) -> None :
228+ def _get_adam_data (self , entity : GwEntityData ) -> None :
233229 """Helper-function for _get_entity_data().
234230
235231 Determine Adam heating-status for on-off heating via valves,
@@ -239,27 +235,27 @@ def _get_adam_data(self, entity: GwEntityData, data: GwEntityData) -> None:
239235 if entity ["dev_class" ] == "heater_central" :
240236 # Indicate heating_state based on valves being open in case of city-provided heating
241237 if self ._on_off_device and isinstance (self ._heating_valves (), int ):
242- data ["binary_sensors" ]["heating_state" ] = self ._heating_valves () != 0
238+ entity ["binary_sensors" ]["heating_state" ] = self ._heating_valves () != 0
243239 # Add cooling_enabled binary_sensor
244240 if (
245- "binary_sensors" in data
246- and "cooling_enabled" not in data ["binary_sensors" ]
241+ "binary_sensors" in entity
242+ and "cooling_enabled" not in entity ["binary_sensors" ]
247243 and self ._cooling_present
248244 ):
249- data ["binary_sensors" ]["cooling_enabled" ] = self ._cooling_enabled
245+ entity ["binary_sensors" ]["cooling_enabled" ] = self ._cooling_enabled
250246 self ._count += 1
251247
252248 # Show the allowed regulation_modes and gateway_modes
253249 if entity ["dev_class" ] == "gateway" :
254250 if self ._reg_allowed_modes :
255- data ["regulation_modes" ] = self ._reg_allowed_modes
251+ entity ["regulation_modes" ] = self ._reg_allowed_modes
256252 self ._count += 1
257253 if self ._gw_allowed_modes :
258- data ["gateway_modes" ] = self ._gw_allowed_modes
254+ entity ["gateway_modes" ] = self ._gw_allowed_modes
259255 self ._count += 1
260256
261257 def _climate_data (
262- self , location_id : str , entity : GwEntityData , data : GwEntityData
258+ self , location_id : str , entity : GwEntityData
263259 ) -> None :
264260 """Helper-function for _get_entity_data().
265261
@@ -270,38 +266,38 @@ def _climate_data(
270266 loc_id = entity ["location" ]
271267
272268 # Presets
273- data ["preset_modes" ] = None
274- data ["active_preset" ] = None
269+ entity ["preset_modes" ] = None
270+ entity ["active_preset" ] = None
275271 self ._count += 2
276272 if presets := self ._presets (loc_id ):
277- data ["preset_modes" ] = list (presets )
278- data ["active_preset" ] = self ._preset (loc_id )
273+ entity ["preset_modes" ] = list (presets )
274+ entity ["active_preset" ] = self ._preset (loc_id )
279275
280276 # Schedule
281- data ["available_schedules" ] = []
282- data ["select_schedule" ] = None
277+ entity ["available_schedules" ] = []
278+ entity ["select_schedule" ] = None
283279 self ._count += 2
284280 avail_schedules , sel_schedule = self ._schedules (loc_id )
285281 if avail_schedules != [NONE ]:
286- data ["available_schedules" ] = avail_schedules
287- data ["select_schedule" ] = sel_schedule
282+ entity ["available_schedules" ] = avail_schedules
283+ entity ["select_schedule" ] = sel_schedule
288284
289285 # Set HA climate HVACMode: auto, heat, heat_cool, cool and off
290- data ["climate_mode" ] = "auto"
286+ entity ["climate_mode" ] = "auto"
291287 self ._count += 1
292288 if sel_schedule in (NONE , OFF ):
293- data ["climate_mode" ] = "heat"
289+ entity ["climate_mode" ] = "heat"
294290 if self ._cooling_present :
295- data ["climate_mode" ] = (
291+ entity ["climate_mode" ] = (
296292 "cool" if self .check_reg_mode ("cooling" ) else "heat_cool"
297293 )
298294
299295 if self .check_reg_mode ("off" ):
300- data ["climate_mode" ] = "off"
296+ entity ["climate_mode" ] = "off"
301297
302298 if NONE not in avail_schedules :
303299 self ._get_schedule_states_with_off (
304- loc_id , avail_schedules , sel_schedule , data
300+ loc_id , avail_schedules , sel_schedule , entity
305301 )
306302
307303 def check_reg_mode (self , mode : str ) -> bool :
@@ -326,7 +322,7 @@ def _get_anna_control_state(self, data: GwEntityData) -> None:
326322 data ["control_state" ] = "cooling"
327323
328324 def _get_schedule_states_with_off (
329- self , location : str , schedules : list [str ], selected : str , data : GwEntityData
325+ self , location : str , schedules : list [str ], selected : str , entity : GwEntityData
330326 ) -> None :
331327 """Collect schedules with states for each thermostat.
332328
@@ -335,11 +331,11 @@ def _get_schedule_states_with_off(
335331 all_off = True
336332 self ._schedule_old_states [location ] = {}
337333 for schedule in schedules :
338- active : bool = schedule == selected and data ["climate_mode" ] == "auto"
334+ active : bool = schedule == selected and entity ["climate_mode" ] == "auto"
339335 self ._schedule_old_states [location ][schedule ] = "off"
340336 if active :
341337 self ._schedule_old_states [location ][schedule ] = "on"
342338 all_off = False
343339
344340 if all_off :
345- data ["select_schedule" ] = OFF
341+ entity ["select_schedule" ] = OFF
0 commit comments