From 9aed5a47ae223cc3afb4a35b85e3064c11ffe2bd Mon Sep 17 00:00:00 2001 From: Joakim Plate Date: Thu, 1 Jun 2023 16:18:49 +0200 Subject: [PATCH] Raise exception instead of hide in logs on zha write (#93571) Raise exception instead of hide in logs Write request that failed parsing of data would fail, yet display as successful in the gui. --- homeassistant/components/zha/core/device.py | 28 +++++++++++-------- homeassistant/components/zha/websocket_api.py | 3 ++ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/zha/core/device.py b/homeassistant/components/zha/core/device.py index 139acb23923..311e876bbc0 100644 --- a/homeassistant/components/zha/core/device.py +++ b/homeassistant/components/zha/core/device.py @@ -740,9 +740,15 @@ class ZHADevice(LogMixin): manufacturer=None, ): """Write a value to a zigbee attribute for a cluster in this entity.""" - cluster = self.async_get_cluster(endpoint_id, cluster_id, cluster_type) - if cluster is None: - return None + try: + cluster: Cluster = self.async_get_cluster( + endpoint_id, cluster_id, cluster_type + ) + except KeyError as exc: + raise ValueError( + f"Cluster {cluster_id} not found on endpoint {endpoint_id} while" + f" writing attribute {attribute} with value {value}" + ) from exc try: response = await cluster.write_attributes( @@ -758,15 +764,13 @@ class ZHADevice(LogMixin): ) return response except zigpy.exceptions.ZigbeeException as exc: - self.debug( - "failed to set attribute: %s %s %s %s %s", - f"{ATTR_VALUE}: {value}", - f"{ATTR_ATTRIBUTE}: {attribute}", - f"{ATTR_CLUSTER_ID}: {cluster_id}", - f"{ATTR_ENDPOINT_ID}: {endpoint_id}", - exc, - ) - return None + raise HomeAssistantError( + f"Failed to set attribute: " + f"{ATTR_VALUE}: {value} " + f"{ATTR_ATTRIBUTE}: {attribute} " + f"{ATTR_CLUSTER_ID}: {cluster_id} " + f"{ATTR_ENDPOINT_ID}: {endpoint_id}" + ) from exc async def issue_cluster_command( self, diff --git a/homeassistant/components/zha/websocket_api.py b/homeassistant/components/zha/websocket_api.py index 2d4126861b4..019a5c50238 100644 --- a/homeassistant/components/zha/websocket_api.py +++ b/homeassistant/components/zha/websocket_api.py @@ -1302,6 +1302,9 @@ def async_load_api(hass: HomeAssistant) -> None: cluster_type=cluster_type, manufacturer=manufacturer, ) + else: + raise ValueError(f"Device with IEEE {str(ieee)} not found") + _LOGGER.debug( ( "Set attribute for: %s: [%s] %s: [%s] %s: [%s] %s: [%s] %s: [%s] %s:"