@@ -129,7 +129,6 @@ def _update_for_cooling(self, entity: GwEntityData) -> None:
129129 and entity ["dev_class" ] == "thermostat"
130130 ):
131131 thermostat = entity ["thermostat" ]
132- sensors = entity ["sensors" ]
133132 temp_dict : ActuatorData = {
134133 "setpoint_low" : thermostat ["setpoint" ],
135134 "setpoint_high" : MAX_SETPOINT ,
@@ -139,14 +138,21 @@ def _update_for_cooling(self, entity: GwEntityData) -> None:
139138 "setpoint_low" : MIN_SETPOINT ,
140139 "setpoint_high" : thermostat ["setpoint" ],
141140 }
142- thermostat .pop ("setpoint" )
141+ thermostat .pop ("setpoint" ) # Add 2 keys, remove 1
143142 temp_dict .update (thermostat )
144143 entity ["thermostat" ] = temp_dict
145- if "setpoint" in sensors :
146- sensors . pop ( "setpoint" )
144+
145+ sensors = entity [ " sensors" ]
147146 sensors ["setpoint_low" ] = temp_dict ["setpoint_low" ]
148147 sensors ["setpoint_high" ] = temp_dict ["setpoint_high" ]
149- self ._count += 2 # add 4, remove 2
148+ # Add 2 more keys, remove 1 when required
149+ if "setpoint" in sensors :
150+ sensors .pop ("setpoint" )
151+ self ._count -= 1
152+
153+ self ._count += (
154+ 3 # add 4 total, remove 1, count the conditional remove separately
155+ )
150156
151157 def _get_location_data (self , loc_id : str ) -> GwEntityData :
152158 """Helper-function for _all_entity_data() and async_update().
@@ -164,8 +170,9 @@ def _get_location_data(self, loc_id: str) -> GwEntityData:
164170 ):
165171 data ["control_state" ] = str (ctrl_state )
166172
167- data ["sensors" ].pop ("setpoint" ) # remove, only used in _control_state()
168- self ._count -= 1
173+ if "setpoint" in data ["sensors" ]:
174+ data ["sensors" ].pop ("setpoint" ) # remove, only used in _control_state()
175+ self ._count -= 1
169176
170177 # Thermostat data (presets, temperatures etc)
171178 self ._climate_data (loc_id , zone , data )
@@ -238,6 +245,7 @@ def _get_adam_data(self, entity: GwEntityData, data: GwEntityData) -> None:
238245 and self ._cooling_present
239246 ):
240247 data ["binary_sensors" ]["cooling_enabled" ] = self ._cooling_enabled
248+ self ._count += 1
241249
242250 # Show the allowed regulation_modes and gateway_modes
243251 if entity ["dev_class" ] == "gateway" :
0 commit comments