From 5e56b173d24214646e7c5b04b2cf50d6b97b4fa2 Mon Sep 17 00:00:00 2001 From: Rohit Date: Tue, 6 Jan 2026 12:16:30 +0530 Subject: [PATCH] components/esp-matter: Fix the delegate initialization flow. Fixes:https://github.com/espressif/esp-matter/issues/1630 --- .../data_model/esp_matter_cluster.cpp | 25 +++++++------------ .../data_model/esp_matter_cluster.h | 6 ----- .../data_model/esp_matter_data_model.cpp | 1 + .../private/esp_matter_data_model_priv.h | 9 +++++++ components/esp_matter/esp_matter_core.cpp | 2 -- 5 files changed, 19 insertions(+), 24 deletions(-) diff --git a/components/esp_matter/data_model/esp_matter_cluster.cpp b/components/esp_matter/data_model/esp_matter_cluster.cpp index f3d925ffc..c1f0117a2 100644 --- a/components/esp_matter/data_model/esp_matter_cluster.cpp +++ b/components/esp_matter/data_model/esp_matter_cluster.cpp @@ -143,24 +143,17 @@ void plugin_init_callback_common() } } -void delegate_init_callback_common() +void delegate_init_callback_common(endpoint_t *endpoint) { - node_t *node = node::get(); - /* Skip delegate_init_callback_common when ESP Matter data model is not used */ - VerifyOrReturn(node); - endpoint_t *endpoint = endpoint::get_first(node); - while (endpoint) { - uint16_t endpoint_id = endpoint::get_id(endpoint); - cluster_t *cluster = get_first(endpoint); - while (cluster) { - /* Delegate server init callback */ - delegate_init_callback_t delegate_init_callback = get_delegate_init_callback(cluster); - if (delegate_init_callback) { - delegate_init_callback(get_delegate_impl(cluster), endpoint_id); - } - cluster = get_next(cluster); + uint16_t endpoint_id = endpoint::get_id(endpoint); + cluster_t *cluster = get_first(endpoint); + while (cluster) { + /* Delegate server init callback */ + delegate_init_callback_t delegate_init_callback = get_delegate_init_callback(cluster); + if (delegate_init_callback) { + delegate_init_callback(get_delegate_impl(cluster), endpoint_id); } - endpoint = endpoint::get_next(endpoint); + cluster = get_next(cluster); } } diff --git a/components/esp_matter/data_model/esp_matter_cluster.h b/components/esp_matter/data_model/esp_matter_cluster.h index 4ea41b346..550b0ec5b 100644 --- a/components/esp_matter/data_model/esp_matter_cluster.h +++ b/components/esp_matter/data_model/esp_matter_cluster.h @@ -35,12 +35,6 @@ namespace cluster { */ void plugin_init_callback_common(); -/** Common cluster delegate init callback - * - * This is the common delegate init callback which calls the delegate init callbacks in the clusters. - */ -void delegate_init_callback_common(); - /** Common cluster add bounds callback * * This is the common add bounds callback which set the bounds to all the attributes of the clusters. diff --git a/components/esp_matter/data_model/esp_matter_data_model.cpp b/components/esp_matter/data_model/esp_matter_data_model.cpp index 84cb26536..3d40fe433 100644 --- a/components/esp_matter/data_model/esp_matter_data_model.cpp +++ b/components/esp_matter/data_model/esp_matter_data_model.cpp @@ -246,6 +246,7 @@ esp_err_t enable(endpoint_t *endpoint) _endpoint_t *current_endpoint = (_endpoint_t *)endpoint; current_endpoint->enabled = true; init_identification(endpoint); + esp_matter::cluster::delegate_init_callback_common(endpoint); return ESP_OK; } diff --git a/components/esp_matter/data_model/private/esp_matter_data_model_priv.h b/components/esp_matter/data_model/private/esp_matter_data_model_priv.h index 0abf39379..d68cec85f 100644 --- a/components/esp_matter/data_model/private/esp_matter_data_model_priv.h +++ b/components/esp_matter/data_model/private/esp_matter_data_model_priv.h @@ -40,6 +40,15 @@ esp_err_t enable_all(); } +namespace cluster { + +/** Common cluster delegate init callback + * + * This is the common delegate init callback which calls the delegate init callbacks in the clusters. + */ +void delegate_init_callback_common(endpoint_t *endpoint); +} + namespace attribute { /** Get the attribute value from the esp-matter storage diff --git a/components/esp_matter/esp_matter_core.cpp b/components/esp_matter/esp_matter_core.cpp index 7e3763df5..7b97e2e9c 100644 --- a/components/esp_matter/esp_matter_core.cpp +++ b/components/esp_matter/esp_matter_core.cpp @@ -225,8 +225,6 @@ static void esp_matter_chip_init_task(intptr_t context) if (endpoint::enable_all() != ESP_OK) { ESP_LOGE(TAG, "Enable all endpoints failure"); } - // Initialise clusters which have delegate implemented - esp_matter::cluster::delegate_init_callback_common(); #endif // CONFIG_ESP_MATTER_ENABLE_DATA_MODEL #if CHIP_CONFIG_ENABLE_ICD_SERVER if (!icd::get_icd_server_enabled()) {