Cleanup zha listener lifecycle (#20789)

This commit is contained in:
David F. Mulcahey authored and Martin Hjelmare committed 2019-02-07 09:23:01 +01:00
1 parent 03ab152c82
commit d4c34c6b02
9 files changed
+2 -39

No files matched your search

@@ -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 = []
@@ -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)
+2 -21
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