Use ZigbeeException instead of DeliveryError in ZHA (#33993)

* Use ZigbeeException instead of DeliveryError

* cleanup get_attributes
This commit is contained in:
David F. Mulcahey 2020-04-11 12:01:49 -04:00 committed by GitHub
parent 8c4a139aeb
commit 946b77e2ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 21 deletions

View file

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

View file

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

View file

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

View file

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

View file

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