From e32669a2d9472487033ec161bc1bba1fc17ade2a Mon Sep 17 00:00:00 2001 From: Alexei Chetroi Date: Fri, 20 Nov 2020 20:02:52 -0500 Subject: [PATCH] Remove zigpy monkey patching (#43456) * Use event handler for incoming messages from zigpy * Bump up zha dependency --- .coveragerc | 1 - homeassistant/components/zha/core/gateway.py | 22 ++++++++++++-------- homeassistant/components/zha/core/patches.py | 18 ---------------- homeassistant/components/zha/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 6 files changed, 16 insertions(+), 31 deletions(-) delete mode 100644 homeassistant/components/zha/core/patches.py diff --git a/.coveragerc b/.coveragerc index be67b91ea61..7186718fecd 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1057,7 +1057,6 @@ omit = homeassistant/components/zha/core/device.py homeassistant/components/zha/core/gateway.py homeassistant/components/zha/core/helpers.py - homeassistant/components/zha/core/patches.py homeassistant/components/zha/core/registries.py homeassistant/components/zha/core/typing.py homeassistant/components/zha/entity.py diff --git a/homeassistant/components/zha/core/gateway.py b/homeassistant/components/zha/core/gateway.py index bdfcf1b24f2..69bf85e47a4 100644 --- a/homeassistant/components/zha/core/gateway.py +++ b/homeassistant/components/zha/core/gateway.py @@ -82,7 +82,6 @@ from .device import ( ZHADevice, ) from .group import GroupMember, ZHAGroup -from .patches import apply_application_controller_patch from .registries import GROUP_ENTITY_DOMAINS from .store import async_get_registry from .typing import ZhaGroupType, ZigpyEndpointType, ZigpyGroupType @@ -155,7 +154,6 @@ class ZHAGateway: ) raise ConfigEntryNotReady from exception - apply_application_controller_patch(self) self.application_controller.add_listener(self) self.application_controller.groups.add_listener(self) self._hass.data[DATA_ZHA][DATA_ZHA_GATEWAY] = self @@ -506,13 +504,6 @@ class ZHAGateway: self._groups[zigpy_group.group_id] = zha_group return zha_group - @callback - def async_device_became_available( - self, sender, profile, cluster, src_ep, dst_ep, message - ): - """Handle tasks when a device becomes available.""" - self.async_update_device(sender, available=True) - @callback def async_update_device( self, sender: zigpy_dev.Device, available: bool = True @@ -639,6 +630,19 @@ class ZHAGateway: unsubscribe() await self.application_controller.pre_shutdown() + def handle_message( + self, + sender: zigpy_dev.Device, + profile: int, + cluster: int, + src_ep: int, + dst_ep: int, + message: bytes, + ) -> None: + """Handle message from a device Event handler.""" + if sender.ieee in self.devices and not self.devices[sender.ieee].available: + self.async_update_device(sender, available=True) + @callback def async_capture_log_levels(): diff --git a/homeassistant/components/zha/core/patches.py b/homeassistant/components/zha/core/patches.py deleted file mode 100644 index 633152e253c..00000000000 --- a/homeassistant/components/zha/core/patches.py +++ /dev/null @@ -1,18 +0,0 @@ -"""Patch functions for Zigbee Home Automation.""" - - -def apply_application_controller_patch(zha_gateway): - """Apply patches to ZHA objects.""" - # Patch handle_message until zigpy can provide an event here - def handle_message(sender, profile, cluster, src_ep, dst_ep, message): - """Handle message from a device.""" - if ( - sender.ieee in zha_gateway.devices - and not zha_gateway.devices[sender.ieee].available - ): - zha_gateway.async_device_became_available( - sender, profile, cluster, src_ep, dst_ep, message - ) - return sender.handle_message(profile, cluster, src_ep, dst_ep, message) - - zha_gateway.application_controller.handle_message = handle_message diff --git a/homeassistant/components/zha/manifest.json b/homeassistant/components/zha/manifest.json index 176338e02c8..34fd5f1f461 100644 --- a/homeassistant/components/zha/manifest.json +++ b/homeassistant/components/zha/manifest.json @@ -9,7 +9,7 @@ "zha-quirks==0.0.46", "zigpy-cc==0.5.2", "zigpy-deconz==0.11.0", - "zigpy==0.27.1", + "zigpy==0.28.0", "zigpy-xbee==0.13.0", "zigpy-zigate==0.7.3", "zigpy-znp==0.2.2" diff --git a/requirements_all.txt b/requirements_all.txt index e972f69aeb8..e4672196675 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2362,7 +2362,7 @@ zigpy-zigate==0.7.3 zigpy-znp==0.2.2 # homeassistant.components.zha -zigpy==0.27.1 +zigpy==0.28.0 # homeassistant.components.zoneminder zm-py==0.4.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index b2025493aaa..6c37691fd2a 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1146,4 +1146,4 @@ zigpy-zigate==0.7.3 zigpy-znp==0.2.2 # homeassistant.components.zha -zigpy==0.27.1 +zigpy==0.28.0