Cleanup zha listener lifecycle (#20789)

This commit is contained in:
David F. Mulcahey 2019-02-07 03:23:01 -05:00 committed by Martin Hjelmare
parent 03ab152c82
commit d4c34c6b02
9 changed files with 2 additions and 39 deletions

View File

@ -147,8 +147,6 @@ async def async_setup_entry(hass, config_entry):
)
zha_gateway = ZHAGateway(hass, config)
hass.bus.async_listen_once(
ha_const.EVENT_HOMEASSISTANT_START, zha_gateway.accept_zigbee_messages)
# Patch handle_message until zigpy can provide an event here
def handle_message(sender, is_reply, profile, cluster,

View File

@ -170,10 +170,6 @@ class ZHADevice:
await self._execute_listener_tasks('async_initialize', from_cache)
_LOGGER.debug('%s: completed initialization', self.name)
async def async_accept_messages(self):
"""Start accepting messages from the zigbee network."""
await self._execute_listener_tasks('accept_messages')
async def _execute_listener_tasks(self, task_name, *args):
"""Gather and execute a set of listener tasks."""
listener_tasks = []

View File

@ -126,13 +126,6 @@ class ZHAGateway:
self._devices[zigpy_device.ieee] = zha_device
return zha_device
async def accept_zigbee_messages(self, _service_or_event):
"""Allow devices to accept zigbee messages."""
accept_messages_calls = []
for device in self.devices.values():
accept_messages_calls.append(device.async_accept_messages())
await asyncio.gather(*accept_messages_calls)
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)

View File

@ -83,7 +83,6 @@ class ListenerStatus(Enum):
CREATED = 1
CONFIGURED = 2
INITIALIZED = 3
LISTENING = 4
class ClusterListener:
@ -99,6 +98,7 @@ class ClusterListener:
[{'attr': 0, 'config': REPORT_CONFIG_DEFAULT}]
)
self._status = ListenerStatus.CREATED
self._cluster.add_listener(self)
@property
def unique_id(self):
@ -156,11 +156,6 @@ class ClusterListener:
"""Initialize listener."""
self._status = ListenerStatus.INITIALIZED
async def accept_messages(self):
"""Attach to the cluster so we can receive messages."""
self._cluster.add_listener(self)
self._status = ListenerStatus.LISTENING
@callback
def cluster_command(self, tsn, command_id, args):
"""Handle commands received to this cluster."""
@ -354,12 +349,6 @@ class IASZoneListener(ClusterListener):
name = 'zone'
def __init__(self, cluster, device):
"""Initialize IASZoneListener."""
super().__init__(cluster, device)
self._cluster.add_listener(self)
self._status = ListenerStatus.LISTENING
@callback
def cluster_command(self, tsn, command_id, args):
"""Handle commands received to this cluster."""
@ -429,10 +418,6 @@ class IASZoneListener(ClusterListener):
await self.get_attribute_value('zone_state', from_cache=from_cache)
await super().async_initialize(from_cache)
async def accept_messages(self):
"""Attach to the cluster so we can receive messages."""
self._status = ListenerStatus.LISTENING
class ActivePowerListener(AttributeListener):
"""Listener that polls active power level."""
@ -625,6 +610,7 @@ class ZDOListener:
self._zha_device = device
self._status = ListenerStatus.CREATED
self._unique_id = "{}_ZDO".format(device.name)
self._cluster.add_listener(self)
@property
def unique_id(self):
@ -651,11 +637,6 @@ class ZDOListener:
"""Permit handler."""
pass
async def accept_messages(self):
"""Attach to the cluster so we can receive messages."""
self._cluster.add_listener(self)
self._status = ListenerStatus.LISTENING
async def async_initialize(self, from_cache):
"""Initialize listener."""
self._status = ListenerStatus.INITIALIZED

View File

@ -161,7 +161,6 @@ def make_entity_id(domain, device, cluster, use_suffix=True):
async def async_enable_traffic(hass, zha_gateway, zha_devices):
"""Allow traffic to flow through the gateway and the zha device."""
await zha_gateway.accept_zigbee_messages({})
for zha_device in zha_devices:
zha_device.update_available(True)
await hass.async_block_till_done()

View File

@ -26,7 +26,6 @@ async def test_fan(hass, config_entry, zha_gateway):
# load up fan domain
await hass.config_entries.async_forward_entry_setup(
config_entry, DOMAIN)
await zha_gateway.accept_zigbee_messages({})
await hass.async_block_till_done()
cluster = zigpy_device.endpoints.get(1).fan

View File

@ -40,7 +40,6 @@ async def test_light(hass, config_entry, zha_gateway):
# load up light domain
await hass.config_entries.async_forward_entry_setup(
config_entry, DOMAIN)
await zha_gateway.accept_zigbee_messages({})
await hass.async_block_till_done()
# on off light

View File

@ -103,7 +103,6 @@ async def async_build_devices(hass, zha_gateway, config_entry, cluster_ids):
# load up sensor domain
await hass.config_entries.async_forward_entry_setup(
config_entry, DOMAIN)
await zha_gateway.accept_zigbee_messages({})
await hass.async_block_till_done()
# put the other relevant info in the device info dict

View File

@ -24,7 +24,6 @@ async def test_switch(hass, config_entry, zha_gateway):
# load up switch domain
await hass.config_entries.async_forward_entry_setup(
config_entry, DOMAIN)
await zha_gateway.accept_zigbee_messages({})
await hass.async_block_till_done()
cluster = zigpy_device.endpoints.get(1).on_off