clean up channel configuration (#22534)

pull/22549/head
David F. Mulcahey 2019-03-29 16:41:04 -04:00 committed by Alexei Chetroi
parent a07919ced2
commit 6401920019
3 changed files with 28 additions and 21 deletions

View File

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

View File

@ -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."""

View File

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