Updated code as per comment in #60676 (#60682)

* Minor code refactor
This commit is contained in:
Penny Wood 2021-12-04 07:28:23 +08:00 committed by GitHub
parent 8c3014169f
commit dcf3bae500
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -207,10 +207,9 @@ class ControllerDevice(ClimateEntity):
"""Handle controller data updates.""" """Handle controller data updates."""
if ctrl is not self._controller: if ctrl is not self._controller:
return return
if not self.available:
return
self.async_write_ha_state() self.async_write_ha_state()
for zone in self.zones.values():
if zone.hass is not None:
zone.async_schedule_update_ha_state()
self.async_on_remove( self.async_on_remove(
async_dispatcher_connect( async_dispatcher_connect(
@ -492,6 +491,21 @@ class ZoneDevice(ClimateEntity):
async def async_added_to_hass(self): async def async_added_to_hass(self):
"""Call on adding to hass.""" """Call on adding to hass."""
@callback
def controller_update(ctrl: Controller) -> None:
"""Handle controller data updates."""
if ctrl.device_uid != self._controller.unique_id:
return
if not self.available:
return
self.async_write_ha_state()
self.async_on_remove(
async_dispatcher_connect(
self.hass, DISPATCH_CONTROLLER_UPDATE, controller_update
)
)
@callback @callback
def zone_update(ctrl: Controller, zone: Zone) -> None: def zone_update(ctrl: Controller, zone: Zone) -> None:
"""Handle zone data updates.""" """Handle zone data updates."""