From 640192001964db17b8a754a36e98757d7e4af292 Mon Sep 17 00:00:00 2001 From: "David F. Mulcahey" Date: Fri, 29 Mar 2019 16:41:04 -0400 Subject: [PATCH] clean up channel configuration (#22534) --- .../components/zha/core/channels/__init__.py | 36 ++++++++++--------- homeassistant/components/zha/core/device.py | 8 ++--- homeassistant/components/zha/core/gateway.py | 5 +++ 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/homeassistant/components/zha/core/channels/__init__.py b/homeassistant/components/zha/core/channels/__init__.py index d8a3918889d..10370c42c66 100644 --- a/homeassistant/components/zha/core/channels/__init__.py +++ b/homeassistant/components/zha/core/channels/__init__.py @@ -15,7 +15,7 @@ from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_send from ..helpers import ( bind_configure_reporting, construct_unique_id, - safe_read, get_attr_id_by_name) + safe_read, get_attr_id_by_name, bind_cluster) from ..const import ( REPORT_CONFIG_DEFAULT, SIGNAL_ATTR_UPDATED, ATTRIBUTE_CHANNEL, EVENT_RELAY_CHANNEL, ZDO_CHANNEL @@ -141,22 +141,24 @@ class ZigbeeChannel: manufacturer_code = self._zha_device.manufacturer_code if self.cluster.cluster_id >= 0xfc00 and manufacturer_code: manufacturer = manufacturer_code - - skip_bind = False # bind cluster only for the 1st configured attr - for report_config in self._report_config: - attr = report_config.get('attr') - min_report_interval, max_report_interval, change = \ - report_config.get('config') - await bind_configure_reporting( - self._unique_id, self.cluster, attr, - min_report=min_report_interval, - max_report=max_report_interval, - reportable_change=change, - skip_bind=skip_bind, - manufacturer=manufacturer - ) - skip_bind = True - await asyncio.sleep(uniform(0.1, 0.5)) + if self.cluster.bind_only: + await bind_cluster(self._unique_id, self.cluster) + else: + skip_bind = False # bind cluster only for the 1st configured attr + for report_config in self._report_config: + attr = report_config.get('attr') + min_report_interval, max_report_interval, change = \ + report_config.get('config') + await bind_configure_reporting( + self._unique_id, self.cluster, attr, + min_report=min_report_interval, + max_report=max_report_interval, + reportable_change=change, + skip_bind=skip_bind, + manufacturer=manufacturer + ) + skip_bind = True + await asyncio.sleep(uniform(0.1, 0.5)) _LOGGER.debug( "%s: finished channel configuration", self._unique_id diff --git a/homeassistant/components/zha/core/device.py b/homeassistant/components/zha/core/device.py index 0ddb67484c6..435ab25acc6 100644 --- a/homeassistant/components/zha/core/device.py +++ b/homeassistant/components/zha/core/device.py @@ -49,7 +49,7 @@ class ZHADevice: self._zha_gateway = zha_gateway self.cluster_channels = {} self._relay_channels = {} - self._all_channels = {} + self._all_channels = [] self._name = "{} {}".format( self.manufacturer, self.model @@ -135,7 +135,7 @@ class ZHADevice: @property def all_channels(self): """Return cluster channels and relay channels for device.""" - return self._all_channels.values() + return self._all_channels @property def available_signal(self): @@ -195,10 +195,10 @@ class ZHADevice: if isinstance(cluster_channel, EventRelayChannel): self._relay_channels[cluster_channel.unique_id] = cluster_channel - self._all_channels[cluster_channel.unique_id] = cluster_channel + self._all_channels.append(cluster_channel) else: self.cluster_channels[cluster_channel.name] = cluster_channel - self._all_channels[cluster_channel.name] = cluster_channel + self._all_channels.append(cluster_channel) async def async_configure(self): """Configure the device.""" diff --git a/homeassistant/components/zha/core/gateway.py b/homeassistant/components/zha/core/gateway.py index 4f1e24aad5b..71e41c2509b 100644 --- a/homeassistant/components/zha/core/gateway.py +++ b/homeassistant/components/zha/core/gateway.py @@ -266,6 +266,11 @@ class ZHAGateway: self._hass, self._config, endpoint_id, endpoint, discovery_infos, device, zha_device, is_new_join ) + if endpoint_id != 0: + for cluster in endpoint.in_clusters.values(): + cluster.bind_only = False + for cluster in endpoint.out_clusters.values(): + cluster.bind_only = True if is_new_join: # configure the device