From 946b77e2ecd70d404fe90a98d7145b0052a7a75b Mon Sep 17 00:00:00 2001 From: "David F. Mulcahey" Date: Sat, 11 Apr 2020 12:01:49 -0400 Subject: [PATCH] Use ZigbeeException instead of DeliveryError in ZHA (#33993) * Use ZigbeeException instead of DeliveryError * cleanup get_attributes --- .../components/zha/core/channels/base.py | 21 +++++++------------ .../components/zha/core/channels/hvac.py | 4 ++-- .../components/zha/core/channels/security.py | 4 ++-- homeassistant/components/zha/core/device.py | 4 ++-- homeassistant/components/zha/fan.py | 4 ++-- 5 files changed, 16 insertions(+), 21 deletions(-) diff --git a/homeassistant/components/zha/core/channels/base.py b/homeassistant/components/zha/core/channels/base.py index 995d109941d..83accc5b86c 100644 --- a/homeassistant/components/zha/core/channels/base.py +++ b/homeassistant/components/zha/core/channels/base.py @@ -56,7 +56,7 @@ def decorate_command(channel, command): ) return result - except (zigpy.exceptions.DeliveryError, asyncio.TimeoutError) as ex: + except (zigpy.exceptions.ZigbeeException, asyncio.TimeoutError) as ex: channel.debug("command failed: %s exception: %s", command.__name__, str(ex)) return ex @@ -135,13 +135,13 @@ class ZigbeeChannel(LogMixin): async def bind(self): """Bind a zigbee cluster. - This also swallows DeliveryError exceptions that are thrown when + This also swallows ZigbeeException exceptions that are thrown when devices are unreachable. """ try: res = await self.cluster.bind() self.debug("bound '%s' cluster: %s", self.cluster.ep_attribute, res[0]) - except (zigpy.exceptions.DeliveryError, asyncio.TimeoutError) as ex: + except (zigpy.exceptions.ZigbeeException, asyncio.TimeoutError) as ex: self.debug( "Failed to bind '%s' cluster: %s", self.cluster.ep_attribute, str(ex) ) @@ -149,7 +149,7 @@ class ZigbeeChannel(LogMixin): async def configure_reporting(self) -> None: """Configure attribute reporting for a cluster. - This also swallows DeliveryError exceptions that are thrown when + This also swallows ZigbeeException exceptions that are thrown when devices are unreachable. """ kwargs = {} @@ -173,7 +173,7 @@ class ZigbeeChannel(LogMixin): reportable_change, res, ) - except (zigpy.exceptions.DeliveryError, asyncio.TimeoutError) as ex: + except (zigpy.exceptions.ZigbeeException, asyncio.TimeoutError) as ex: self.debug( "failed to set reporting for '%s' attr on '%s' cluster: %s", attr_name, @@ -263,20 +263,15 @@ class ZigbeeChannel(LogMixin): only_cache=from_cache, manufacturer=manufacturer, ) - results = { - attribute: result.get(attribute) - for attribute in attributes - if result.get(attribute) is not None - } - except (asyncio.TimeoutError, zigpy.exceptions.DeliveryError) as ex: + return result + except (asyncio.TimeoutError, zigpy.exceptions.ZigbeeException) as ex: self.debug( "failed to get attributes '%s' on '%s' cluster: %s", attributes, self.cluster.ep_attribute, str(ex), ) - results = {} - return results + return {} def log(self, level, msg, *args): """Log a message.""" diff --git a/homeassistant/components/zha/core/channels/hvac.py b/homeassistant/components/zha/core/channels/hvac.py index bd90b907d3b..3c58ff946b9 100644 --- a/homeassistant/components/zha/core/channels/hvac.py +++ b/homeassistant/components/zha/core/channels/hvac.py @@ -1,7 +1,7 @@ """HVAC channels module for Zigbee Home Automation.""" import logging -from zigpy.exceptions import DeliveryError +from zigpy.exceptions import ZigbeeException import zigpy.zcl.clusters.hvac as hvac from homeassistant.core import callback @@ -31,7 +31,7 @@ class FanChannel(ZigbeeChannel): try: await self.cluster.write_attributes({"fan_mode": value}) - except DeliveryError as ex: + except ZigbeeException as ex: self.error("Could not set speed: %s", ex) return diff --git a/homeassistant/components/zha/core/channels/security.py b/homeassistant/components/zha/core/channels/security.py index 914c1133116..b2b6f74c0de 100644 --- a/homeassistant/components/zha/core/channels/security.py +++ b/homeassistant/components/zha/core/channels/security.py @@ -7,7 +7,7 @@ https://home-assistant.io/integrations/zha/ import asyncio import logging -from zigpy.exceptions import DeliveryError +from zigpy.exceptions import ZigbeeException import zigpy.zcl.clusters.security as security from homeassistant.core import callback @@ -151,7 +151,7 @@ class IASZoneChannel(ZigbeeChannel): self._cluster.ep_attribute, res[0], ) - except DeliveryError as ex: + except ZigbeeException as ex: self.debug( "Failed to write cie_addr: %s to '%s' cluster: %s", str(ieee), diff --git a/homeassistant/components/zha/core/device.py b/homeassistant/components/zha/core/device.py index 5782ce23083..b4947d121e4 100644 --- a/homeassistant/components/zha/core/device.py +++ b/homeassistant/components/zha/core/device.py @@ -511,7 +511,7 @@ class ZHADevice(LogMixin): response, ) return response - except zigpy.exceptions.DeliveryError as exc: + except zigpy.exceptions.ZigbeeException as exc: self.debug( "failed to set attribute: %s %s %s %s %s", f"{ATTR_VALUE}: {value}", @@ -563,7 +563,7 @@ class ZHADevice(LogMixin): """Remove this device from the provided zigbee group.""" try: await self._zigpy_device.remove_from_group(group_id) - except (zigpy.exceptions.DeliveryError, asyncio.TimeoutError) as ex: + except (zigpy.exceptions.ZigbeeException, asyncio.TimeoutError) as ex: self.debug( "Failed to remove device '%s' from group: 0x%04x ex: %s", self._zigpy_device.ieee, diff --git a/homeassistant/components/zha/fan.py b/homeassistant/components/zha/fan.py index 8a9dc2691fc..c7a13a4f34f 100644 --- a/homeassistant/components/zha/fan.py +++ b/homeassistant/components/zha/fan.py @@ -3,7 +3,7 @@ import functools import logging from typing import List -from zigpy.exceptions import DeliveryError +from zigpy.exceptions import ZigbeeException import zigpy.zcl.clusters.hvac as hvac from homeassistant.components.fan import ( @@ -177,7 +177,7 @@ class FanGroup(BaseFan, ZhaGroupEntity): """Set the speed of the fan.""" try: await self._fan_channel.write_attributes({"fan_mode": value}) - except DeliveryError as ex: + except ZigbeeException as ex: self.error("Could not set speed: %s", ex) return