@@ -80,15 +80,34 @@ def _add_entities() -> None:
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 .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+ else :
93+ for device_id in coordinator .new_devices :
94+ device = coordinator .data .devices [device_id ]
95+ if device [DEV_CLASS ] in MASTER_THERMOSTATS :
96+ entities .append (
97+ PlugwiseClimateEntity (
98+ coordinator , device_id , homekit_enabled
99+ ) # pw-beta homekit emulation
100+ )
101+ LOGGER .debug ("Add climate %s" , device [ATTR_NAME ])
102+
103+ for device_id in coordinator .new_zones :
104+ thermostat = coordinator .data .zones [device_id ]
105+ entities .append (
106+ PlugwiseClimateEntity (
107+ coordinator , device_id , homekit_enabled
108+ ) # pw-beta homekit emulation
109+ )
110+ LOGGER .debug ("Add climate %s" , thermostat [ATTR_NAME ])
92111
93112 async_add_entities (entities )
94113
@@ -118,14 +137,18 @@ def __init__(
118137 super ().__init__ (coordinator , device_id )
119138
120139 self ._homekit_enabled = homekit_enabled # pw-beta homekit emulation
140+ self ._location = device_id
141+ if (location := self .device_or_zone .get (LOCATION )) is not None :
142+ self ._location = location
143+
121144 gateway_id : str = coordinator .data .gateway [GATEWAY_ID ]
122145 self .gateway_data = coordinator .data .devices [gateway_id ]
123146
124- self ._attr_max_temp = min (self .device [THERMOSTAT ][UPPER_BOUND ], 35.0 )
125- self ._attr_min_temp = self .device [THERMOSTAT ][LOWER_BOUND ]
147+ self ._attr_max_temp = min (self .device_or_zone [THERMOSTAT ][UPPER_BOUND ], 35.0 )
148+ self ._attr_min_temp = self .device_or_zone [THERMOSTAT ][LOWER_BOUND ]
126149 # Ensure we don't drop below 0.1
127150 self ._attr_target_temperature_step = max (
128- self .device [THERMOSTAT ][RESOLUTION ], 0.1
151+ self .device_or_zone [THERMOSTAT ][RESOLUTION ], 0.1
129152 )
130153 self ._attr_unique_id = f"{ device_id } -climate"
131154
@@ -143,7 +166,7 @@ def __init__(
143166 self ._attr_supported_features |= (
144167 ClimateEntityFeature .TURN_OFF | ClimateEntityFeature .TURN_ON
145168 )
146- if presets := self .device ["preset_modes" ]: # can be NONE
169+ if presets := self .device_or_zone ["preset_modes" ]: # can be NONE
147170 self ._attr_supported_features |= ClimateEntityFeature .PRESET_MODE
148171 self ._attr_preset_modes = presets
149172
@@ -164,7 +187,7 @@ def _previous_action_mode(self, coordinator: PlugwiseDataUpdateCoordinator) -> N
164187 @property
165188 def current_temperature (self ) -> float :
166189 """Return the current temperature."""
167- return self .device [SENSORS ][ATTR_TEMPERATURE ]
190+ return self .device_or_zone [SENSORS ][ATTR_TEMPERATURE ]
168191
169192 @property
170193 def target_temperature (self ) -> float :
@@ -173,29 +196,29 @@ def target_temperature(self) -> float:
173196 Connected to the HVACMode combination of AUTO-HEAT.
174197 """
175198
176- return self .device [THERMOSTAT ][TARGET_TEMP ]
199+ return self .device_or_zone [THERMOSTAT ][TARGET_TEMP ]
177200
178201 @property
179202 def target_temperature_high (self ) -> float :
180203 """Return the temperature we try to reach in case of cooling.
181204
182205 Connected to the HVACMode combination of AUTO-HEAT_COOL.
183206 """
184- return self .device [THERMOSTAT ][TARGET_TEMP_HIGH ]
207+ return self .device_or_zone [THERMOSTAT ][TARGET_TEMP_HIGH ]
185208
186209 @property
187210 def target_temperature_low (self ) -> float :
188211 """Return the heating temperature we try to reach in case of heating.
189212
190213 Connected to the HVACMode combination AUTO-HEAT_COOL.
191214 """
192- return self .device [THERMOSTAT ][TARGET_TEMP_LOW ]
215+ return self .device_or_zone [THERMOSTAT ][TARGET_TEMP_LOW ]
193216
194217 @property
195218 def hvac_mode (self ) -> HVACMode :
196219 """Return HVAC operation ie. auto, cool, heat, heat_cool, or off mode."""
197220 if (
198- mode := self .device [CLIMATE_MODE ]
221+ mode := self .device_or_zone [CLIMATE_MODE ]
199222 ) is None or mode not in self .hvac_modes : # pw-beta add to Core
200223 return HVACMode .HEAT # pragma: no cover
201224 # pw-beta homekit emulation
@@ -214,7 +237,7 @@ def hvac_modes(self) -> list[HVACMode]:
214237 ):
215238 hvac_modes .append (HVACMode .OFF )
216239
217- if AVAILABLE_SCHEDULES in self .device :
240+ if AVAILABLE_SCHEDULES in self .device_or_zone :
218241 hvac_modes .append (HVACMode .AUTO )
219242
220243 if self .cdr_gateway [COOLING_PRESENT ]:
@@ -237,7 +260,7 @@ def hvac_action(self) -> HVACAction: # pw-beta add to Core
237260 self ._previous_action_mode (self .coordinator )
238261
239262 # Adam provides the hvac_action for each thermostat
240- if (control_state := self .device .get (CONTROL_STATE )) in (HVACAction .COOLING , HVACAction .HEATING , HVACAction .PREHEATING ):
263+ if (control_state := self .device_or_zone .get (CONTROL_STATE )) in (HVACAction .COOLING , HVACAction .HEATING , HVACAction .PREHEATING ):
241264 return cast (HVACAction , control_state )
242265 if control_state == HVACMode .OFF :
243266 return HVACAction .IDLE
@@ -255,7 +278,7 @@ def hvac_action(self) -> HVACAction: # pw-beta add to Core
255278 @property
256279 def preset_mode (self ) -> str | None :
257280 """Return the current preset mode."""
258- return self .device [ACTIVE_PRESET ]
281+ return self .device_or_zone [ACTIVE_PRESET ]
259282
260283 @plugwise_command
261284 async def async_set_temperature (self , ** kwargs : Any ) -> None :
@@ -273,7 +296,7 @@ async def async_set_temperature(self, **kwargs: Any) -> None:
273296 if mode := kwargs .get (ATTR_HVAC_MODE ):
274297 await self .async_set_hvac_mode (mode )
275298
276- await self .coordinator .api .set_temperature (self .device [ LOCATION ] , data )
299+ await self .coordinator .api .set_temperature (self ._location , data )
277300
278301 @plugwise_command
279302 async def async_set_hvac_mode (self , hvac_mode : HVACMode ) -> None :
@@ -286,7 +309,7 @@ async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
286309
287310 if hvac_mode != HVACMode .OFF :
288311 await self .coordinator .api .set_schedule_state (
289- self .device [ LOCATION ] ,
312+ self ._location ,
290313 STATE_ON if hvac_mode == HVACMode .AUTO else STATE_OFF ,
291314 )
292315
@@ -303,11 +326,11 @@ async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
303326 await self .async_set_preset_mode (PRESET_AWAY ) # pragma: no cover
304327 if (
305328 self ._homekit_mode in [HVACMode .HEAT , HVACMode .HEAT_COOL ]
306- and self .device [ACTIVE_PRESET ] == PRESET_AWAY
329+ and self .device_or_zone [ACTIVE_PRESET ] == PRESET_AWAY
307330 ): # pragma: no cover
308331 await self .async_set_preset_mode (PRESET_HOME ) # pragma: no cover
309332
310333 @plugwise_command
311334 async def async_set_preset_mode (self , preset_mode : str ) -> None :
312335 """Set the preset mode."""
313- await self .coordinator .api .set_preset (self .device [ LOCATION ] , preset_mode )
336+ await self .coordinator .api .set_preset (self ._location , preset_mode )
0 commit comments