mirror of
https://github.com/espressif/esp-matter.git
synced 2026-04-27 19:13:13 +00:00
components/esp_matter: propagate error code from attribute report on v1.4.2
attribute::report() was ignoring the return value from set_val() and always returning ESP_OK. This hid errors like ESP_ERR_NOT_SUPPORTED for internally managed attributes (e.g., BooleanState::StateValue). This fix: - Propagates the error from set_val() back to the caller - Checks return value of get_val() in report() - Adds void cast to intentionally unchecked get_data_from_attr_val() call in update() Related: https://github.com/espressif/esp-matter/issues/1724 Backport of !1441 (main)
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2021 Espressif Systems (Shanghai) PTE LTD
|
// Copyright 2021-2026 Espressif Systems (Shanghai) PTE LTD
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
@@ -536,7 +536,7 @@ static esp_err_t console_set_handler(int argc, char **argv)
|
|||||||
attribute_id);
|
attribute_id);
|
||||||
VerifyOrReturnError(matter_attribute, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Matter attribute not found"));
|
VerifyOrReturnError(matter_attribute, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Matter attribute not found"));
|
||||||
|
|
||||||
/* Use the type to create the val and then update te attribute */
|
/* Use the type to create the val and then update the attribute */
|
||||||
esp_matter_val_type_t type = get_val_type_from_attribute_type(matter_attribute->attributeType);
|
esp_matter_val_type_t type = get_val_type_from_attribute_type(matter_attribute->attributeType);
|
||||||
esp_matter_attr_val_t val = esp_matter_invalid(NULL);
|
esp_matter_attr_val_t val = esp_matter_invalid(NULL);
|
||||||
if (type == ESP_MATTER_VAL_TYPE_BOOLEAN) {
|
if (type == ESP_MATTER_VAL_TYPE_BOOLEAN) {
|
||||||
@@ -2069,7 +2069,8 @@ esp_err_t update(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_i
|
|||||||
}
|
}
|
||||||
return ESP_ERR_NO_MEM;
|
return ESP_ERR_NO_MEM;
|
||||||
}
|
}
|
||||||
get_data_from_attr_val(val, &attribute_type, &attribute_size, value);
|
/* Ignore return value: identical call succeeded above with NULL value buffer */
|
||||||
|
(void)get_data_from_attr_val(val, &attribute_type, &attribute_size, value);
|
||||||
|
|
||||||
/* Update matter */
|
/* Update matter */
|
||||||
Status status = Status::Success;
|
Status status = Status::Success;
|
||||||
@@ -2112,7 +2113,15 @@ esp_err_t report(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_i
|
|||||||
|
|
||||||
/* Update attribute */
|
/* Update attribute */
|
||||||
esp_matter_attr_val_t raw_val = esp_matter_invalid(NULL);
|
esp_matter_attr_val_t raw_val = esp_matter_invalid(NULL);
|
||||||
attribute::get_val(attribute, &raw_val);
|
esp_err_t err = attribute::get_val(attribute, &raw_val);
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to get the attribute value for Endpoint 0x%04" PRIX16 "'s Cluster 0x%08" PRIX32 "'s Attribute 0x%08" PRIX32 " err: %d",
|
||||||
|
endpoint_id, cluster_id, attribute_id, err);
|
||||||
|
if (lock_status == lock::SUCCESS) {
|
||||||
|
lock::chip_stack_unlock();
|
||||||
|
}
|
||||||
|
return err;
|
||||||
|
}
|
||||||
if (val->type != raw_val.type) {
|
if (val->type != raw_val.type) {
|
||||||
ESP_LOGE(TAG, "Attribute type mismatch when trying to report Endpoint 0x%04" PRIX16 "'s Cluster 0x%08" PRIX32 "'s Attribute 0x%08" PRIX32,
|
ESP_LOGE(TAG, "Attribute type mismatch when trying to report Endpoint 0x%04" PRIX16 "'s Cluster 0x%08" PRIX32 "'s Attribute 0x%08" PRIX32,
|
||||||
endpoint_id, cluster_id, attribute_id);
|
endpoint_id, cluster_id, attribute_id);
|
||||||
@@ -2121,7 +2130,15 @@ esp_err_t report(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_i
|
|||||||
}
|
}
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
attribute::set_val(attribute, val);
|
err = attribute::set_val(attribute, val);
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
ESP_LOGE(TAG, "Failed to set attribute value for Endpoint 0x%04" PRIX16 "'s Cluster 0x%08" PRIX32 "'s Attribute 0x%08" PRIX32 " err: %d",
|
||||||
|
endpoint_id, cluster_id, attribute_id, err);
|
||||||
|
if (lock_status == lock::SUCCESS) {
|
||||||
|
lock::chip_stack_unlock();
|
||||||
|
}
|
||||||
|
return err;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
/* Report attribute */
|
/* Report attribute */
|
||||||
MatterReportingAttributeChangeCallback(endpoint_id, cluster_id, attribute_id);
|
MatterReportingAttributeChangeCallback(endpoint_id, cluster_id, attribute_id);
|
||||||
|
|||||||
Reference in New Issue
Block a user