5252class SmileData (SmileHelper ):
5353 """The Plugwise Smile main class."""
5454
55- def update_for_cooling (self , devices : dict [ str , DeviceData ] ) -> None :
55+ def update_for_cooling (self , device : DeviceData ) -> None :
5656 """Helper-function for adding/updating various cooling-related values."""
57- for device in list (devices .values ()):
58- # For Adam + on/off cooling, modify heating_state and cooling_state
59- # based on provided info by Plugwise
60- if (
61- self .smile_name == "Adam"
62- and device ["dev_class" ] == "heater_central"
63- and self ._on_off_device
64- and self ._cooling_active
65- and device ["binary_sensors" ]["heating_state" ]
66- ):
67- device ["binary_sensors" ]["cooling_state" ] = True
68- device ["binary_sensors" ]["heating_state" ] = False
69-
70- # Add setpoint_low and setpoint_high when cooling is enabled
71- if device ["dev_class" ] not in ZONE_THERMOSTATS :
72- continue
73-
74- # For heating + cooling, replace setpoint with setpoint_high/_low
75- if self ._cooling_present :
76- thermostat = device ["thermostat" ]
77- sensors = device ["sensors" ]
78- max_setpoint = MAX_SETPOINT
79- min_setpoint = MIN_SETPOINT
80- if self ._sched_setpoints is not None :
81- max_setpoint = self ._sched_setpoints [1 ]
82- min_setpoint = self ._sched_setpoints [0 ]
83-
84- temp_dict : ActuatorData = {
85- "setpoint_low" : thermostat ["setpoint" ],
86- "setpoint_high" : max_setpoint ,
57+ # For Adam + on/off cooling, modify heating_state and cooling_state
58+ # based on provided info by Plugwise
59+ if (
60+ self .smile_name == "Adam"
61+ and device ["dev_class" ] == "heater_central"
62+ and self ._on_off_device
63+ and self ._cooling_active
64+ and device ["binary_sensors" ]["heating_state" ]
65+ ):
66+ device ["binary_sensors" ]["cooling_state" ] = True
67+ device ["binary_sensors" ]["heating_state" ] = False
68+
69+ # Add setpoint_low and setpoint_high when cooling is enabled
70+ if device ["dev_class" ] not in ZONE_THERMOSTATS :
71+ return
72+
73+ # For heating + cooling, replace setpoint with setpoint_high/_low
74+ if self ._cooling_present :
75+ thermostat = device ["thermostat" ]
76+ sensors = device ["sensors" ]
77+ max_setpoint = MAX_SETPOINT
78+ min_setpoint = MIN_SETPOINT
79+ if device ["selected_schedule" ] != "None" :
80+ max_setpoint = self ._sched_setpoints [1 ]
81+ min_setpoint = self ._sched_setpoints [0 ]
82+
83+ temp_dict : ActuatorData = {
84+ "setpoint_low" : thermostat ["setpoint" ],
85+ "setpoint_high" : max_setpoint ,
86+ }
87+ if self ._cooling_enabled :
88+ temp_dict = {
89+ "setpoint_low" : min_setpoint ,
90+ "setpoint_high" : thermostat ["setpoint" ],
8791 }
88- if self ._cooling_active :
89- temp_dict = {
90- "setpoint_low" : min_setpoint ,
91- "setpoint_high" : thermostat ["setpoint" ],
92- }
93- if "setpoint" in sensors :
94- sensors .pop ("setpoint" )
95- sensors ["setpoint_low" ] = temp_dict ["setpoint_low" ]
96- sensors ["setpoint_high" ] = temp_dict ["setpoint_high" ]
97- thermostat .pop ("setpoint" )
98- temp_dict .update (thermostat )
99- device ["thermostat" ] = temp_dict
92+ thermostat .pop ("setpoint" )
93+ temp_dict .update (thermostat )
94+ device ["thermostat" ] = temp_dict
95+ if "setpoint" in sensors :
96+ sensors .pop ("setpoint" )
97+ sensors ["setpoint_low" ] = temp_dict ["setpoint_low" ]
98+ sensors ["setpoint_high" ] = temp_dict ["setpoint_high" ]
10099
101100 def _all_device_data (self ) -> None :
102101 """Helper-function for get_all_devices().
@@ -111,8 +110,8 @@ def _all_device_data(self) -> None:
111110 device_id , data , device , bs_dict , s_dict , sw_dict
112111 )
113112
114- # After all device data has been determined, add/update for cooling
115- self .update_for_cooling (self .gw_devices )
113+ # Update for cooling
114+ self .update_for_cooling (self .gw_devices [ device_id ] )
116115
117116 self .gw_data .update (
118117 {"smile_name" : self .smile_name , "gateway_id" : self .gateway_id }
@@ -255,16 +254,16 @@ def _check_availability(
255254 # OpenTherm device
256255 if details ["dev_class" ] == "heater_central" and details ["name" ] != "OnOff" :
257256 device_data ["available" ] = True
258- for data in list ( self ._notifications .values () ):
259- for msg in list ( data .values () ):
257+ for data in self ._notifications .values ():
258+ for msg in data .values ():
260259 if "no OpenTherm communication" in msg :
261260 device_data ["available" ] = False
262261
263262 # Smartmeter
264263 if details ["dev_class" ] == "smartmeter" :
265264 device_data ["available" ] = True
266- for data in list ( self ._notifications .values () ):
267- for msg in list ( data .values () ):
265+ for data in self ._notifications .values ():
266+ for msg in data .values ():
268267 if "P1 does not seem to be connected to a smart meter" in msg :
269268 device_data ["available" ] = False
270269
@@ -551,7 +550,7 @@ async def async_update(self) -> list[GatewayData | dict[str, DeviceData]]:
551550
552551 for dev_id , dev_dict in self .gw_devices .items ():
553552 data = self ._get_device_data (dev_id )
554- for key , value in list ( data .items () ):
553+ for key , value in data .items ():
555554 if key in dev_dict :
556555 dev_dict [key ] = value # type: ignore [literal-required]
557556
@@ -560,7 +559,7 @@ async def async_update(self) -> list[GatewayData | dict[str, DeviceData]]:
560559 if item == "binary_sensors" :
561560 notifs = self ._notifications
562561 if item in dev_dict :
563- for key , value in list ( data .items () ):
562+ for key , value in data .items ():
564563 update_helper (
565564 data ,
566565 self .gw_devices ,
@@ -571,8 +570,8 @@ async def async_update(self) -> list[GatewayData | dict[str, DeviceData]]:
571570 notifs ,
572571 )
573572
574- # After all device data has been determined, add/update for cooling
575- self .update_for_cooling (self . gw_devices )
573+ # Update for cooling
574+ self .update_for_cooling (dev_dict )
576575
577576 return [self .gw_data , self .gw_devices ]
578577
0 commit comments