From 958c7e95ed34904356d19cfa98a93d9979e1fad0 Mon Sep 17 00:00:00 2001 From: WanqQixiang Date: Fri, 12 Apr 2024 14:59:40 +0800 Subject: [PATCH] Do not use minimum unused endpoint id if server instance is disabled or ESP-Matter data model is disabled Fixes CON-1120 --- components/esp_matter/esp_matter_core.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/components/esp_matter/esp_matter_core.cpp b/components/esp_matter/esp_matter_core.cpp index 067b198ae..4492d41dd 100644 --- a/components/esp_matter/esp_matter_core.cpp +++ b/components/esp_matter/esp_matter_core.cpp @@ -224,6 +224,8 @@ namespace node { static _node_t *node = NULL; +#if defined(CONFIG_ESP_MATTER_ENABLE_MATTER_SERVER) && defined(CONFIG_ESP_MATTE_ENABLE_DATA_MODEL) +// If Matter server or ESP-Matter data model is not enabled. we will never use minimum unused endpoint id. static esp_err_t store_min_unused_endpoint_id() { if (!node || !esp_matter_started) { @@ -287,7 +289,7 @@ static esp_err_t read_min_unused_endpoint_id() } return err; } - +#endif // defined(CONFIG_ESP_MATTER_ENABLE_MATTER_SERVER) && defined(CONFIG_ESP_MATTE_ENABLE_DATA_MODEL) } /* node */ namespace cluster { @@ -1083,14 +1085,13 @@ esp_err_t start(event_callback_t callback, intptr_t callback_arg) return err; } esp_matter_started = true; -#ifdef CONFIG_ESP_MATTER_ENABLE_MATTER_SERVER - // If Matter server is not enabled. we will never use minimum unused endpoint id. +#if defined(CONFIG_ESP_MATTER_ENABLE_MATTER_SERVER) && defined(CONFIG_ESP_MATTE_ENABLE_DATA_MODEL) err = node::read_min_unused_endpoint_id(); // If the min_unused_endpoint_id is not found, we will write the current min_unused_endpoint_id in nvs. if (err == ESP_ERR_NVS_NOT_FOUND) { err = node::store_min_unused_endpoint_id(); } -#endif +#endif // defined(CONFIG_ESP_MATTER_ENABLE_MATTER_SERVER) && defined(CONFIG_ESP_MATTE_ENABLE_DATA_MODEL) return err; } @@ -1930,11 +1931,12 @@ endpoint_t *create(node_t *node, uint8_t flags, void *priv_data) endpoint->parent_endpoint_id = chip::kInvalidEndpointId; endpoint->flags = flags; endpoint->priv_data = priv_data; - +#if defined(CONFIG_ESP_MATTER_ENABLE_MATTER_SERVER) && defined(CONFIG_ESP_MATTE_ENABLE_DATA_MODEL) /* Store */ if (esp_matter_started) { node::store_min_unused_endpoint_id(); } +#endif // defined(CONFIG_ESP_MATTER_ENABLE_MATTER_SERVER) && defined(CONFIG_ESP_MATTE_ENABLE_DATA_MODEL) /* Add */ _endpoint_t *previous_endpoint = NULL;