clean up channel configuration (#22534)

This commit is contained in:
David F. Mulcahey 2019-03-29 16:41:04 -04:00 committed by Paulus Schoutsen
parent 53595e76d8
commit b7bc520a0e
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 homeassistant.helpers.dispatcher import async_dispatcher_send
from ..helpers import ( from ..helpers import (
bind_configure_reporting, construct_unique_id, 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 ( from ..const import (
REPORT_CONFIG_DEFAULT, SIGNAL_ATTR_UPDATED, ATTRIBUTE_CHANNEL, REPORT_CONFIG_DEFAULT, SIGNAL_ATTR_UPDATED, ATTRIBUTE_CHANNEL,
EVENT_RELAY_CHANNEL, ZDO_CHANNEL EVENT_RELAY_CHANNEL, ZDO_CHANNEL
@ -141,22 +141,24 @@ class ZigbeeChannel:
manufacturer_code = self._zha_device.manufacturer_code manufacturer_code = self._zha_device.manufacturer_code
if self.cluster.cluster_id >= 0xfc00 and manufacturer_code: if self.cluster.cluster_id >= 0xfc00 and manufacturer_code:
manufacturer = manufacturer_code manufacturer = manufacturer_code
if self.cluster.bind_only:
skip_bind = False # bind cluster only for the 1st configured attr await bind_cluster(self._unique_id, self.cluster)
for report_config in self._report_config: else:
attr = report_config.get('attr') skip_bind = False # bind cluster only for the 1st configured attr
min_report_interval, max_report_interval, change = \ for report_config in self._report_config:
report_config.get('config') attr = report_config.get('attr')
await bind_configure_reporting( min_report_interval, max_report_interval, change = \
self._unique_id, self.cluster, attr, report_config.get('config')
min_report=min_report_interval, await bind_configure_reporting(
max_report=max_report_interval, self._unique_id, self.cluster, attr,
reportable_change=change, min_report=min_report_interval,
skip_bind=skip_bind, max_report=max_report_interval,
manufacturer=manufacturer reportable_change=change,
) skip_bind=skip_bind,
skip_bind = True manufacturer=manufacturer
await asyncio.sleep(uniform(0.1, 0.5)) )
skip_bind = True
await asyncio.sleep(uniform(0.1, 0.5))
_LOGGER.debug( _LOGGER.debug(
"%s: finished channel configuration", "%s: finished channel configuration",
self._unique_id self._unique_id

View File

@ -49,7 +49,7 @@ class ZHADevice:
self._zha_gateway = zha_gateway self._zha_gateway = zha_gateway
self.cluster_channels = {} self.cluster_channels = {}
self._relay_channels = {} self._relay_channels = {}
self._all_channels = {} self._all_channels = []
self._name = "{} {}".format( self._name = "{} {}".format(
self.manufacturer, self.manufacturer,
self.model self.model
@ -135,7 +135,7 @@ class ZHADevice:
@property @property
def all_channels(self): def all_channels(self):
"""Return cluster channels and relay channels for device.""" """Return cluster channels and relay channels for device."""
return self._all_channels.values() return self._all_channels
@property @property
def available_signal(self): def available_signal(self):
@ -195,10 +195,10 @@ class ZHADevice:
if isinstance(cluster_channel, EventRelayChannel): if isinstance(cluster_channel, EventRelayChannel):
self._relay_channels[cluster_channel.unique_id] = cluster_channel 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: else:
self.cluster_channels[cluster_channel.name] = cluster_channel 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): async def async_configure(self):
"""Configure the device.""" """Configure the device."""

View File

@ -266,6 +266,11 @@ class ZHAGateway:
self._hass, self._config, endpoint_id, endpoint, self._hass, self._config, endpoint_id, endpoint,
discovery_infos, device, zha_device, is_new_join 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: if is_new_join:
# configure the device # configure the device