@@ -76,19 +76,30 @@ async def async_setup_entry(
7676 @callback
7777 def _add_entities () -> None :
7878 """Add Entities during init and runtime."""
79- if not coordinator .new_devices :
79+ if not ( coordinator .new_devices or coordinator . new_zones ) :
8080 return
8181
8282 entities : list [PlugwiseClimateEntity ] = []
83- for device_id in coordinator .new_devices :
84- device = coordinator .data . devices [ device_id ]
85- if device [ DEV_CLASS ] in MASTER_THERMOSTATS :
83+ if coordinator .new_zones :
84+ for device_id in coordinator .new_zones :
85+ thermostat = coordinator . data . zones [ device_id ]
8686 entities .append (
8787 PlugwiseClimateEntity (
8888 coordinator , device_id , homekit_enabled
8989 ) # pw-beta homekit emulation
9090 )
91- LOGGER .debug ("Add climate %s" , device [ATTR_NAME ])
91+ LOGGER .debug ("Add climate %s" , thermostat [ATTR_NAME ])
92+
93+ if coordinator .new_devices :
94+ for device_id in coordinator .new_devices :
95+ device = coordinator .data .devices [device_id ]
96+ if device [DEV_CLASS ] in MASTER_THERMOSTATS :
97+ entities .append (
98+ PlugwiseClimateEntity (
99+ coordinator , device_id , homekit_enabled
100+ ) # pw-beta homekit emulation
101+ )
102+ LOGGER .debug ("Add climate %s" , device [ATTR_NAME ])
92103
93104 async_add_entities (entities )
94105
@@ -118,14 +129,18 @@ def __init__(
118129 super ().__init__ (coordinator , device_id )
119130
120131 self ._homekit_enabled = homekit_enabled # pw-beta homekit emulation
132+ self ._location = device_id
133+ if (location := self .device_or_zone .get (LOCATION )) is not None :
134+ self ._location = location
135+
121136 gateway_id : str = coordinator .data .gateway [GATEWAY_ID ]
122137 self .gateway_data = coordinator .data .devices [gateway_id ]
123138
124- self ._attr_max_temp = min (self .device [THERMOSTAT ][UPPER_BOUND ], 35.0 )
125- self ._attr_min_temp = self .device [THERMOSTAT ][LOWER_BOUND ]
139+ self ._attr_max_temp = min (self .device_or_zone [THERMOSTAT ][UPPER_BOUND ], 35.0 )
140+ self ._attr_min_temp = self .device_or_zone [THERMOSTAT ][LOWER_BOUND ]
126141 # Ensure we don't drop below 0.1
127142 self ._attr_target_temperature_step = max (
128- self .device [THERMOSTAT ][RESOLUTION ], 0.1
143+ self .device_or_zone [THERMOSTAT ][RESOLUTION ], 0.1
129144 )
130145 self ._attr_unique_id = f"{ device_id } -climate"
131146
@@ -143,7 +158,7 @@ def __init__(
143158 self ._attr_supported_features |= (
144159 ClimateEntityFeature .TURN_OFF | ClimateEntityFeature .TURN_ON
145160 )
146- if presets := self .device ["preset_modes" ]: # can be NONE
161+ if presets := self .device_or_zone ["preset_modes" ]: # can be NONE
147162 self ._attr_supported_features |= ClimateEntityFeature .PRESET_MODE
148163 self ._attr_preset_modes = presets
149164
@@ -164,7 +179,7 @@ def _previous_action_mode(self, coordinator: PlugwiseDataUpdateCoordinator) -> N
164179 @property
165180 def current_temperature (self ) -> float :
166181 """Return the current temperature."""
167- return self .device [SENSORS ][ATTR_TEMPERATURE ]
182+ return self .device_or_zone [SENSORS ][ATTR_TEMPERATURE ]
168183
169184 @property
170185 def target_temperature (self ) -> float :
@@ -173,29 +188,29 @@ def target_temperature(self) -> float:
173188 Connected to the HVACMode combination of AUTO-HEAT.
174189 """
175190
176- return self .device [THERMOSTAT ][TARGET_TEMP ]
191+ return self .device_or_zone [THERMOSTAT ][TARGET_TEMP ]
177192
178193 @property
179194 def target_temperature_high (self ) -> float :
180195 """Return the temperature we try to reach in case of cooling.
181196
182197 Connected to the HVACMode combination of AUTO-HEAT_COOL.
183198 """
184- return self .device [THERMOSTAT ][TARGET_TEMP_HIGH ]
199+ return self .device_or_zone [THERMOSTAT ][TARGET_TEMP_HIGH ]
185200
186201 @property
187202 def target_temperature_low (self ) -> float :
188203 """Return the heating temperature we try to reach in case of heating.
189204
190205 Connected to the HVACMode combination AUTO-HEAT_COOL.
191206 """
192- return self .device [THERMOSTAT ][TARGET_TEMP_LOW ]
207+ return self .device_or_zone [THERMOSTAT ][TARGET_TEMP_LOW ]
193208
194209 @property
195210 def hvac_mode (self ) -> HVACMode :
196211 """Return HVAC operation ie. auto, cool, heat, heat_cool, or off mode."""
197212 if (
198- mode := self .device [CLIMATE_MODE ]
213+ mode := self .device_or_zone [CLIMATE_MODE ]
199214 ) is None or mode not in self .hvac_modes : # pw-beta add to Core
200215 return HVACMode .HEAT # pragma: no cover
201216 # pw-beta homekit emulation
@@ -214,7 +229,7 @@ def hvac_modes(self) -> list[HVACMode]:
214229 ):
215230 hvac_modes .append (HVACMode .OFF )
216231
217- if AVAILABLE_SCHEDULES in self .device :
232+ if AVAILABLE_SCHEDULES in self .device_or_zone :
218233 hvac_modes .append (HVACMode .AUTO )
219234
220235 if self .cdr_gateway [COOLING_PRESENT ]:
@@ -237,7 +252,7 @@ def hvac_action(self) -> HVACAction: # pw-beta add to Core
237252 self ._previous_action_mode (self .coordinator )
238253
239254 # Adam provides the hvac_action for each thermostat
240- if (control_state := self .device .get (CONTROL_STATE )) in (HVACAction .COOLING , HVACAction .HEATING , HVACAction .PREHEATING ):
255+ if (control_state := self .device_or_zone .get (CONTROL_STATE )) in (HVACAction .COOLING , HVACAction .HEATING , HVACAction .PREHEATING ):
241256 return cast (HVACAction , control_state )
242257 if control_state == HVACMode .OFF :
243258 return HVACAction .IDLE
@@ -255,7 +270,7 @@ def hvac_action(self) -> HVACAction: # pw-beta add to Core
255270 @property
256271 def preset_mode (self ) -> str | None :
257272 """Return the current preset mode."""
258- return self .device [ACTIVE_PRESET ]
273+ return self .device_or_zone [ACTIVE_PRESET ]
259274
260275 @plugwise_command
261276 async def async_set_temperature (self , ** kwargs : Any ) -> None :
@@ -273,7 +288,7 @@ async def async_set_temperature(self, **kwargs: Any) -> None:
273288 if mode := kwargs .get (ATTR_HVAC_MODE ):
274289 await self .async_set_hvac_mode (mode )
275290
276- await self .coordinator .api .set_temperature (self .device [ LOCATION ] , data )
291+ await self .coordinator .api .set_temperature (self ._location , data )
277292
278293 @plugwise_command
279294 async def async_set_hvac_mode (self , hvac_mode : HVACMode ) -> None :
@@ -286,7 +301,7 @@ async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
286301
287302 if hvac_mode != HVACMode .OFF :
288303 await self .coordinator .api .set_schedule_state (
289- self .device [ LOCATION ] ,
304+ self ._location ,
290305 STATE_ON if hvac_mode == HVACMode .AUTO else STATE_OFF ,
291306 )
292307
@@ -303,11 +318,11 @@ async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
303318 await self .async_set_preset_mode (PRESET_AWAY ) # pragma: no cover
304319 if (
305320 self ._homekit_mode in [HVACMode .HEAT , HVACMode .HEAT_COOL ]
306- and self .device [ACTIVE_PRESET ] == PRESET_AWAY
321+ and self .device_or_zone [ACTIVE_PRESET ] == PRESET_AWAY
307322 ): # pragma: no cover
308323 await self .async_set_preset_mode (PRESET_HOME ) # pragma: no cover
309324
310325 @plugwise_command
311326 async def async_set_preset_mode (self , preset_mode : str ) -> None :
312327 """Set the preset mode."""
313- await self .coordinator .api .set_preset (self .device [ LOCATION ] , preset_mode )
328+ await self .coordinator .api .set_preset (self ._location , preset_mode )
0 commit comments