diff --git a/homeassistant/components/zha/__init__.py b/homeassistant/components/zha/__init__.py index ae08b2cac40..b8ef5c40838 100644 --- a/homeassistant/components/zha/__init__.py +++ b/homeassistant/components/zha/__init__.py @@ -152,10 +152,14 @@ async def async_setup_entry(hass, config_entry): def handle_message(sender, is_reply, profile, cluster, src_ep, dst_ep, tsn, command_id, args): """Handle message from a device.""" - if sender.last_seen is None and not sender.initializing: - if sender.ieee in zha_gateway.devices: - device = zha_gateway.devices[sender.ieee] - device.update_available(True) + if not sender.initializing and sender.ieee in zha_gateway.devices and \ + not zha_gateway.devices[sender.ieee].available: + hass.async_create_task( + zha_gateway.async_device_became_available( + sender, is_reply, profile, cluster, src_ep, dst_ep, tsn, + command_id, args + ) + ) return sender.handle_message( is_reply, profile, cluster, src_ep, dst_ep, tsn, command_id, args) diff --git a/homeassistant/components/zha/core/gateway.py b/homeassistant/components/zha/core/gateway.py index 16d834bdecb..02ed1d73699 100644 --- a/homeassistant/components/zha/core/gateway.py +++ b/homeassistant/components/zha/core/gateway.py @@ -126,6 +126,18 @@ class ZHAGateway: self._devices[zigpy_device.ieee] = zha_device return zha_device + async def async_device_became_available( + self, sender, is_reply, profile, cluster, src_ep, dst_ep, tsn, + command_id, args): + """Handle tasks when a device becomes available.""" + self.async_update_device(sender) + + def async_update_device(self, sender): + """Update device that has just become available.""" + if sender.ieee in self.devices: + device = self.devices[sender.ieee] + device.update_available(True) + async def async_device_initialized(self, device, is_new_join): """Handle device joined and basic information discovered (async).""" zha_device = await self._get_or_create_device(device)