1
mirror of https://github.com/home-assistant/core synced 2024-09-06 10:29:55 +02:00

Run tasks when ZHA devices become available (#20998)

* use tasks for message interception

* update available handling

* review comments and cleaned up check

* review comments
This commit is contained in:
David F. Mulcahey 2019-02-13 08:52:29 -05:00 committed by GitHub
parent 8db8a58763
commit d692251e62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 4 deletions

View File

@ -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)

View File

@ -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)