Use ZigbeeException instead of DeliveryError in ZHA (#33993)
* Use ZigbeeException instead of DeliveryError * cleanup get_attributes
This commit is contained in:
parent
8c4a139aeb
commit
946b77e2ec
5 changed files with 16 additions and 21 deletions
|
@ -56,7 +56,7 @@ def decorate_command(channel, command):
|
||||||
)
|
)
|
||||||
return result
|
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))
|
channel.debug("command failed: %s exception: %s", command.__name__, str(ex))
|
||||||
return ex
|
return ex
|
||||||
|
|
||||||
|
@ -135,13 +135,13 @@ class ZigbeeChannel(LogMixin):
|
||||||
async def bind(self):
|
async def bind(self):
|
||||||
"""Bind a zigbee cluster.
|
"""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.
|
devices are unreachable.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
res = await self.cluster.bind()
|
res = await self.cluster.bind()
|
||||||
self.debug("bound '%s' cluster: %s", self.cluster.ep_attribute, res[0])
|
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(
|
self.debug(
|
||||||
"Failed to bind '%s' cluster: %s", self.cluster.ep_attribute, str(ex)
|
"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:
|
async def configure_reporting(self) -> None:
|
||||||
"""Configure attribute reporting for a cluster.
|
"""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.
|
devices are unreachable.
|
||||||
"""
|
"""
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
|
@ -173,7 +173,7 @@ class ZigbeeChannel(LogMixin):
|
||||||
reportable_change,
|
reportable_change,
|
||||||
res,
|
res,
|
||||||
)
|
)
|
||||||
except (zigpy.exceptions.DeliveryError, asyncio.TimeoutError) as ex:
|
except (zigpy.exceptions.ZigbeeException, asyncio.TimeoutError) as ex:
|
||||||
self.debug(
|
self.debug(
|
||||||
"failed to set reporting for '%s' attr on '%s' cluster: %s",
|
"failed to set reporting for '%s' attr on '%s' cluster: %s",
|
||||||
attr_name,
|
attr_name,
|
||||||
|
@ -263,20 +263,15 @@ class ZigbeeChannel(LogMixin):
|
||||||
only_cache=from_cache,
|
only_cache=from_cache,
|
||||||
manufacturer=manufacturer,
|
manufacturer=manufacturer,
|
||||||
)
|
)
|
||||||
results = {
|
return result
|
||||||
attribute: result.get(attribute)
|
except (asyncio.TimeoutError, zigpy.exceptions.ZigbeeException) as ex:
|
||||||
for attribute in attributes
|
|
||||||
if result.get(attribute) is not None
|
|
||||||
}
|
|
||||||
except (asyncio.TimeoutError, zigpy.exceptions.DeliveryError) as ex:
|
|
||||||
self.debug(
|
self.debug(
|
||||||
"failed to get attributes '%s' on '%s' cluster: %s",
|
"failed to get attributes '%s' on '%s' cluster: %s",
|
||||||
attributes,
|
attributes,
|
||||||
self.cluster.ep_attribute,
|
self.cluster.ep_attribute,
|
||||||
str(ex),
|
str(ex),
|
||||||
)
|
)
|
||||||
results = {}
|
return {}
|
||||||
return results
|
|
||||||
|
|
||||||
def log(self, level, msg, *args):
|
def log(self, level, msg, *args):
|
||||||
"""Log a message."""
|
"""Log a message."""
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""HVAC channels module for Zigbee Home Automation."""
|
"""HVAC channels module for Zigbee Home Automation."""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from zigpy.exceptions import DeliveryError
|
from zigpy.exceptions import ZigbeeException
|
||||||
import zigpy.zcl.clusters.hvac as hvac
|
import zigpy.zcl.clusters.hvac as hvac
|
||||||
|
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
|
@ -31,7 +31,7 @@ class FanChannel(ZigbeeChannel):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await self.cluster.write_attributes({"fan_mode": value})
|
await self.cluster.write_attributes({"fan_mode": value})
|
||||||
except DeliveryError as ex:
|
except ZigbeeException as ex:
|
||||||
self.error("Could not set speed: %s", ex)
|
self.error("Could not set speed: %s", ex)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ https://home-assistant.io/integrations/zha/
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from zigpy.exceptions import DeliveryError
|
from zigpy.exceptions import ZigbeeException
|
||||||
import zigpy.zcl.clusters.security as security
|
import zigpy.zcl.clusters.security as security
|
||||||
|
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
|
@ -151,7 +151,7 @@ class IASZoneChannel(ZigbeeChannel):
|
||||||
self._cluster.ep_attribute,
|
self._cluster.ep_attribute,
|
||||||
res[0],
|
res[0],
|
||||||
)
|
)
|
||||||
except DeliveryError as ex:
|
except ZigbeeException as ex:
|
||||||
self.debug(
|
self.debug(
|
||||||
"Failed to write cie_addr: %s to '%s' cluster: %s",
|
"Failed to write cie_addr: %s to '%s' cluster: %s",
|
||||||
str(ieee),
|
str(ieee),
|
||||||
|
|
|
@ -511,7 +511,7 @@ class ZHADevice(LogMixin):
|
||||||
response,
|
response,
|
||||||
)
|
)
|
||||||
return response
|
return response
|
||||||
except zigpy.exceptions.DeliveryError as exc:
|
except zigpy.exceptions.ZigbeeException as exc:
|
||||||
self.debug(
|
self.debug(
|
||||||
"failed to set attribute: %s %s %s %s %s",
|
"failed to set attribute: %s %s %s %s %s",
|
||||||
f"{ATTR_VALUE}: {value}",
|
f"{ATTR_VALUE}: {value}",
|
||||||
|
@ -563,7 +563,7 @@ class ZHADevice(LogMixin):
|
||||||
"""Remove this device from the provided zigbee group."""
|
"""Remove this device from the provided zigbee group."""
|
||||||
try:
|
try:
|
||||||
await self._zigpy_device.remove_from_group(group_id)
|
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(
|
self.debug(
|
||||||
"Failed to remove device '%s' from group: 0x%04x ex: %s",
|
"Failed to remove device '%s' from group: 0x%04x ex: %s",
|
||||||
self._zigpy_device.ieee,
|
self._zigpy_device.ieee,
|
||||||
|
|
|
@ -3,7 +3,7 @@ import functools
|
||||||
import logging
|
import logging
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from zigpy.exceptions import DeliveryError
|
from zigpy.exceptions import ZigbeeException
|
||||||
import zigpy.zcl.clusters.hvac as hvac
|
import zigpy.zcl.clusters.hvac as hvac
|
||||||
|
|
||||||
from homeassistant.components.fan import (
|
from homeassistant.components.fan import (
|
||||||
|
@ -177,7 +177,7 @@ class FanGroup(BaseFan, ZhaGroupEntity):
|
||||||
"""Set the speed of the fan."""
|
"""Set the speed of the fan."""
|
||||||
try:
|
try:
|
||||||
await self._fan_channel.write_attributes({"fan_mode": value})
|
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)
|
self.error("Could not set speed: %s", ex)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue