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.
This commit is contained in:
Joakim Plate 2023-06-01 16:18:49 +02:00 committed by GitHub
parent 1f0e235b99
commit 9aed5a47ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 12 deletions

View file

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

View file

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