From 227b8bdf8a9008ae53eed5c31d6843d4157463fd Mon Sep 17 00:00:00 2001 From: "David F. Mulcahey" Date: Tue, 18 Jun 2019 11:36:28 -0400 Subject: [PATCH] Better pairing for Xiaomi devices in ZHA (#24564) * better xiaomi pairing * cleanup. --- .../components/zha/core/channels/__init__.py | 39 +++++++++---------- .../components/zha/core/channels/security.py | 3 ++ 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/homeassistant/components/zha/core/channels/__init__.py b/homeassistant/components/zha/core/channels/__init__.py index 83ade589465..162ef5a59e4 100644 --- a/homeassistant/components/zha/core/channels/__init__.py +++ b/homeassistant/components/zha/core/channels/__init__.py @@ -14,7 +14,7 @@ from random import uniform from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_send from ..helpers import ( - bind_configure_reporting, construct_unique_id, + configure_reporting, construct_unique_id, safe_read, get_attr_id_by_name, bind_cluster) from ..const import ( REPORT_CONFIG_DEFAULT, SIGNAL_ATTR_UPDATED, ATTRIBUTE_CHANNEL, @@ -133,26 +133,25 @@ class ZigbeeChannel: """Set cluster binding and attribute reporting.""" manufacturer = None manufacturer_code = self._zha_device.manufacturer_code - if self.cluster.cluster_id >= 0xfc00 and manufacturer_code: - manufacturer = manufacturer_code - if self.cluster.bind_only: + # Xiaomi devices don't need this and it disrupts pairing + if self._zha_device.manufacturer != 'LUMI': + if self.cluster.cluster_id >= 0xfc00 and manufacturer_code: + manufacturer = manufacturer_code 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)) + if not self.cluster.bind_only: + for report_config in self._report_config: + attr = report_config.get('attr') + min_report_interval, max_report_interval, change = \ + report_config.get('config') + await configure_reporting( + self._unique_id, self.cluster, attr, + min_report=min_report_interval, + max_report=max_report_interval, + reportable_change=change, + manufacturer=manufacturer + ) + await asyncio.sleep(uniform(0.1, 0.5)) + _LOGGER.debug( "%s: finished channel configuration", self._unique_id diff --git a/homeassistant/components/zha/core/channels/security.py b/homeassistant/components/zha/core/channels/security.py index 03b50b7c7ba..a69ab692da5 100644 --- a/homeassistant/components/zha/core/channels/security.py +++ b/homeassistant/components/zha/core/channels/security.py @@ -35,6 +35,9 @@ class IASZoneChannel(ZigbeeChannel): async def async_configure(self): """Configure IAS device.""" + # Xiaomi devices don't need this and it disrupts pairing + if self._zha_device.manufacturer == 'LUMI': + return from zigpy.exceptions import DeliveryError _LOGGER.debug("%s: started IASZoneChannel configuration", self._unique_id)