@@ -90,6 +90,15 @@ def _add_entities() -> None:
9090 )
9191 LOGGER .debug ("Add climate %s" , device [ATTR_NAME ])
9292
93+ for device_id in coordinator .new_zones :
94+ thermostat = coordinator .data .zones [device_id ]
95+ entities .append (
96+ PlugwiseClimateEntity (
97+ coordinator , device_id , homekit_enabled
98+ ) # pw-beta homekit emulation
99+ )
100+ LOGGER .debug ("Add climate %s" , thermostat [ATTR_NAME ])
101+
93102 async_add_entities (entities )
94103
95104 _add_entities ()
@@ -118,14 +127,18 @@ def __init__(
118127 super ().__init__ (coordinator , device_id )
119128
120129 self ._homekit_enabled = homekit_enabled # pw-beta homekit emulation
130+ self ._location = device_id
131+ if (location := self .device_or_zone .get (LOCATION )) is not None :
132+ self ._location = location
133+
121134 gateway_id : str = coordinator .data .gateway [GATEWAY_ID ]
122135 self .gateway_data = coordinator .data .devices [gateway_id ]
123136
124- self ._attr_max_temp = min (self .device [THERMOSTAT ][UPPER_BOUND ], 35.0 )
125- self ._attr_min_temp = self .device [THERMOSTAT ][LOWER_BOUND ]
137+ self ._attr_max_temp = min (self .device_or_zone [THERMOSTAT ][UPPER_BOUND ], 35.0 )
138+ self ._attr_min_temp = self .device_or_zone [THERMOSTAT ][LOWER_BOUND ]
126139 # Ensure we don't drop below 0.1
127140 self ._attr_target_temperature_step = max (
128- self .device [THERMOSTAT ][RESOLUTION ], 0.1
141+ self .device_or_zone [THERMOSTAT ][RESOLUTION ], 0.1
129142 )
130143 self ._attr_unique_id = f"{ device_id } -climate"
131144
@@ -143,7 +156,7 @@ def __init__(
143156 self ._attr_supported_features |= (
144157 ClimateEntityFeature .TURN_OFF | ClimateEntityFeature .TURN_ON
145158 )
146- if presets := self .device ["preset_modes" ]: # can be NONE
159+ if presets := self .device_or_zone ["preset_modes" ]: # can be NONE
147160 self ._attr_supported_features |= ClimateEntityFeature .PRESET_MODE
148161 self ._attr_preset_modes = presets
149162
@@ -164,7 +177,7 @@ def _previous_action_mode(self, coordinator: PlugwiseDataUpdateCoordinator) -> N
164177 @property
165178 def current_temperature (self ) -> float :
166179 """Return the current temperature."""
167- return self .device [SENSORS ][ATTR_TEMPERATURE ]
180+ return self .device_or_zone [SENSORS ][ATTR_TEMPERATURE ]
168181
169182 @property
170183 def target_temperature (self ) -> float :
@@ -173,29 +186,29 @@ def target_temperature(self) -> float:
173186 Connected to the HVACMode combination of AUTO-HEAT.
174187 """
175188
176- return self .device [THERMOSTAT ][TARGET_TEMP ]
189+ return self .device_or_zone [THERMOSTAT ][TARGET_TEMP ]
177190
178191 @property
179192 def target_temperature_high (self ) -> float :
180193 """Return the temperature we try to reach in case of cooling.
181194
182195 Connected to the HVACMode combination of AUTO-HEAT_COOL.
183196 """
184- return self .device [THERMOSTAT ][TARGET_TEMP_HIGH ]
197+ return self .device_or_zone [THERMOSTAT ][TARGET_TEMP_HIGH ]
185198
186199 @property
187200 def target_temperature_low (self ) -> float :
188201 """Return the heating temperature we try to reach in case of heating.
189202
190203 Connected to the HVACMode combination AUTO-HEAT_COOL.
191204 """
192- return self .device [THERMOSTAT ][TARGET_TEMP_LOW ]
205+ return self .device_or_zone [THERMOSTAT ][TARGET_TEMP_LOW ]
193206
194207 @property
195208 def hvac_mode (self ) -> HVACMode :
196209 """Return HVAC operation ie. auto, cool, heat, heat_cool, or off mode."""
197210 if (
198- mode := self .device [CLIMATE_MODE ]
211+ mode := self .device_or_zone [CLIMATE_MODE ]
199212 ) is None or mode not in self .hvac_modes : # pw-beta add to Core
200213 return HVACMode .HEAT # pragma: no cover
201214 # pw-beta homekit emulation
@@ -214,7 +227,7 @@ def hvac_modes(self) -> list[HVACMode]:
214227 ):
215228 hvac_modes .append (HVACMode .OFF )
216229
217- if AVAILABLE_SCHEDULES in self .device :
230+ if AVAILABLE_SCHEDULES in self .device_or_zone :
218231 hvac_modes .append (HVACMode .AUTO )
219232
220233 if self .cdr_gateway [COOLING_PRESENT ]:
@@ -237,14 +250,14 @@ def hvac_action(self) -> HVACAction: # pw-beta add to Core
237250 self ._previous_action_mode (self .coordinator )
238251
239252 # Adam provides the hvac_action for each thermostat
240- if (control_state := self .device .get (CONTROL_STATE )) in (HVACAction .COOLING , HVACAction .HEATING , HVACAction .PREHEATING ):
253+ if (control_state := self .device_or_zone .get (CONTROL_STATE )) in (HVACAction .COOLING , HVACAction .HEATING , HVACAction .PREHEATING ):
241254 return cast (HVACAction , control_state )
242255 if control_state == HVACMode .OFF :
243256 return HVACAction .IDLE
244257
245258 # Anna
246259 heater : str = self .coordinator .data .gateway ["heater_id" ]
247- heater_data = self .coordinator .data .devices [heater ]
260+ heater_data = self .coordinator .data .device_or_zone [heater ]
248261 if heater_data [BINARY_SENSORS ][HEATING_STATE ]:
249262 return HVACAction .HEATING
250263 if heater_data [BINARY_SENSORS ].get (COOLING_STATE , False ):
@@ -255,7 +268,7 @@ def hvac_action(self) -> HVACAction: # pw-beta add to Core
255268 @property
256269 def preset_mode (self ) -> str | None :
257270 """Return the current preset mode."""
258- return self .device [ACTIVE_PRESET ]
271+ return self .device_or_zone [ACTIVE_PRESET ]
259272
260273 @plugwise_command
261274 async def async_set_temperature (self , ** kwargs : Any ) -> None :
@@ -273,7 +286,7 @@ async def async_set_temperature(self, **kwargs: Any) -> None:
273286 if mode := kwargs .get (ATTR_HVAC_MODE ):
274287 await self .async_set_hvac_mode (mode )
275288
276- await self .coordinator .api .set_temperature (self .device [ LOCATION ] , data )
289+ await self .coordinator .api .set_temperature (self ._location , data )
277290
278291 @plugwise_command
279292 async def async_set_hvac_mode (self , hvac_mode : HVACMode ) -> None :
@@ -286,7 +299,7 @@ async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
286299
287300 if hvac_mode != HVACMode .OFF :
288301 await self .coordinator .api .set_schedule_state (
289- self .device [ LOCATION ] ,
302+ self ._location ,
290303 STATE_ON if hvac_mode == HVACMode .AUTO else STATE_OFF ,
291304 )
292305
@@ -303,11 +316,11 @@ async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
303316 await self .async_set_preset_mode (PRESET_AWAY ) # pragma: no cover
304317 if (
305318 self ._homekit_mode in [HVACMode .HEAT , HVACMode .HEAT_COOL ]
306- and self .device [ACTIVE_PRESET ] == PRESET_AWAY
319+ and self .device_or_zone [ACTIVE_PRESET ] == PRESET_AWAY
307320 ): # pragma: no cover
308321 await self .async_set_preset_mode (PRESET_HOME ) # pragma: no cover
309322
310323 @plugwise_command
311324 async def async_set_preset_mode (self , preset_mode : str ) -> None :
312325 """Set the preset mode."""
313- await self .coordinator .api .set_preset (self .device [ LOCATION ] , preset_mode )
326+ await self .coordinator .api .set_preset (self ._location , preset_mode )
0 commit comments