From 5f79a45627647b985fe429c8865c5c4087cb2714 Mon Sep 17 00:00:00 2001 From: Rohit Jadhav Date: Wed, 16 Aug 2023 15:45:31 +0530 Subject: [PATCH] Change return type of add() API to esp_err from endpoint. --- RELEASE_NOTES.md | 9 + components/esp_matter/esp_matter_endpoint.cpp | 480 +++++++++++------- components/esp_matter/esp_matter_endpoint.h | 60 +-- .../esp_matter_bridge/esp_matter_bridge.cpp | 32 +- 4 files changed, 371 insertions(+), 210 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 07f9e595f..6bbc9024c 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -86,6 +86,15 @@ Features - RainMaker integration. - Zigbee to Matter and BLE Mesh to Matter Bridge. +# 25-Sep-2023 + +API Change + +``` +esp_err_t add(endpoint_t *endpoint, config_t *config) +``` +- Above API returns the esp_err instread of endpoint. + Known Issues ------------ - BLE memory is not freed if the device has already been commissioned on bootup. diff --git a/components/esp_matter/esp_matter_endpoint.cpp b/components/esp_matter/esp_matter_endpoint.cpp index 908fcaac0..e0fae6b7a 100644 --- a/components/esp_matter/esp_matter_endpoint.cpp +++ b/components/esp_matter/esp_matter_endpoint.cpp @@ -36,16 +36,21 @@ uint8_t get_device_type_version() endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) { endpoint_t *endpoint = endpoint::create(node, flags, priv_data); - return add(endpoint, config); + add(endpoint, config); + return endpoint; } -endpoint_t *add(endpoint_t *endpoint, config_t *config) +esp_err_t add(endpoint_t *endpoint, config_t *config) { if (!endpoint) { ESP_LOGE(TAG, "Endpoint cannot be NULL"); - return NULL; + return ESP_ERR_INVALID_ARG; + } + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err); + return err; } - add_device_type(endpoint, get_device_type_id(), get_device_type_version()); descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER); access_control::create(endpoint, &(config->access_control), CLUSTER_FLAG_SERVER); @@ -68,7 +73,7 @@ endpoint_t *add(endpoint_t *endpoint, config_t *config) icd_management::feature::check_in_protocol_support::get_id()); #endif - return endpoint; + return ESP_OK; } } /* root_node */ @@ -86,33 +91,32 @@ uint8_t get_device_type_version() endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) { endpoint_t *endpoint = endpoint::create(node, flags, priv_data); - if (endpoint) { - return add(endpoint, config); - } + add(endpoint, config); return endpoint; } -endpoint_t *add(endpoint_t *endpoint, config_t *config) +esp_err_t add(endpoint_t *endpoint, config_t *config) { if (!endpoint) { - ESP_LOGE(TAG, "Could not create endpoint"); - return NULL; - } + ESP_LOGE(TAG, "Endpoint cannot be NULL"); + return ESP_ERR_INVALID_ARG; + } esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); if (err != ESP_OK) { - ESP_LOGE(TAG, "Failed to add device type: err: %d", err); + ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err); + return err; } cluster_t *cluster = descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER); if (!cluster) { - return NULL; + return ESP_ERR_INVALID_STATE; } cluster = power_source::create(endpoint, &(config->power_source), CLUSTER_FLAG_SERVER, ESP_MATTER_NONE_FEATURE_ID); if (!cluster) { - return NULL; + return ESP_ERR_INVALID_STATE; } - return endpoint; + return ESP_OK; } } /** power_source_device **/ @@ -131,16 +135,21 @@ uint8_t get_device_type_version() endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) { endpoint_t *endpoint = endpoint::create(node, flags, priv_data); - return add(endpoint, config); + add(endpoint, config); + return endpoint; } -endpoint_t *add(endpoint_t *endpoint, config_t *config) +esp_err_t add(endpoint_t *endpoint, config_t *config) { if (!endpoint) { ESP_LOGE(TAG, "Endpoint cannot be NULL"); - return NULL; + return ESP_ERR_INVALID_ARG; + } + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err); + return err; } - add_device_type(endpoint, get_device_type_id(), get_device_type_version()); descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER); cluster_t *identify_cluster = identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER); @@ -149,7 +158,7 @@ endpoint_t *add(endpoint_t *endpoint, config_t *config) scenes::create(endpoint, &(config->scenes), CLUSTER_FLAG_SERVER); on_off::create(endpoint, &(config->on_off), CLUSTER_FLAG_SERVER, on_off::feature::lighting::get_id()); - return endpoint; + return ESP_OK; } } /* on_off_light */ @@ -168,16 +177,21 @@ uint8_t get_device_type_version() endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) { endpoint_t *endpoint = endpoint::create(node, flags, priv_data); - return add(endpoint, config); + add(endpoint, config); + return endpoint; } -endpoint_t *add(endpoint_t *endpoint, config_t *config) +esp_err_t add(endpoint_t *endpoint, config_t *config) { if (!endpoint) { ESP_LOGE(TAG, "Endpoint cannot be NULL"); - return NULL; + return ESP_ERR_INVALID_ARG; + } + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err); + return err; } - add_device_type(endpoint, get_device_type_id(), get_device_type_version()); descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER); cluster_t *identify_cluster = identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER); @@ -188,7 +202,7 @@ endpoint_t *add(endpoint_t *endpoint, config_t *config) level_control::create(endpoint, &(config->level_control), CLUSTER_FLAG_SERVER, level_control::feature::on_off::get_id() | level_control::feature::lighting::get_id()); - return endpoint; + return ESP_OK; } } /* dimmable_light */ @@ -206,16 +220,21 @@ uint8_t get_device_type_version() endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) { endpoint_t *endpoint = endpoint::create(node, flags, priv_data); - return add(endpoint, config); + add(endpoint, config); + return endpoint; } -endpoint_t *add(endpoint_t *endpoint, config_t *config) +esp_err_t add(endpoint_t *endpoint, config_t *config) { - if (!endpoint) { + if (!endpoint) { ESP_LOGE(TAG, "Endpoint cannot be NULL"); - return NULL; + return ESP_ERR_INVALID_ARG; + } + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err); + return err; } - add_device_type(endpoint, get_device_type_id(), get_device_type_version()); descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER); cluster_t *identify_cluster = identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER); @@ -228,7 +247,7 @@ endpoint_t *add(endpoint_t *endpoint, config_t *config) color_control::create(endpoint, &(config->color_control), CLUSTER_FLAG_SERVER, color_control::feature::color_temperature::get_id()); - return endpoint; + return ESP_OK; } } /* color_temperature_light */ @@ -247,16 +266,21 @@ uint8_t get_device_type_version() endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) { endpoint_t *endpoint = endpoint::create(node, flags, priv_data); - return add(endpoint, config); + add(endpoint, config); + return endpoint; } -endpoint_t *add(endpoint_t *endpoint, config_t *config) +esp_err_t add(endpoint_t *endpoint, config_t *config) { if (!endpoint) { ESP_LOGE(TAG, "Endpoint cannot be NULL"); - return NULL; + return ESP_ERR_INVALID_ARG; + } + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err); + return err; } - add_device_type(endpoint, get_device_type_id(), get_device_type_version()); descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER); cluster_t *identify_cluster = identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER); @@ -272,8 +296,8 @@ endpoint_t *add(endpoint_t *endpoint, config_t *config) level_control::feature::on_off::get_id() | level_control::feature::lighting::get_id()); color_control::create(endpoint, &(config->color_control), CLUSTER_FLAG_SERVER, color_control::feature::color_temperature::get_id() | color_control::feature::xy::get_id()); + return ESP_OK; - return endpoint; } } /* extended_color_light */ @@ -291,23 +315,28 @@ uint8_t get_device_type_version() endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) { endpoint_t *endpoint = endpoint::create(node, flags, priv_data); - return add(endpoint, config); + add(endpoint, config); + return endpoint; } -endpoint_t *add(endpoint_t *endpoint, config_t *config) +esp_err_t add(endpoint_t *endpoint, config_t *config) { if (!endpoint) { ESP_LOGE(TAG, "Endpoint cannot be NULL"); - return NULL; + return ESP_ERR_INVALID_ARG; + } + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err); + return err; } - add_device_type(endpoint, get_device_type_id(), get_device_type_version()); descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER); identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER | CLUSTER_FLAG_CLIENT); binding::create(endpoint, &(config->binding), CLUSTER_FLAG_SERVER); on_off::create(endpoint, NULL, CLUSTER_FLAG_CLIENT, ESP_MATTER_NONE_FEATURE_ID); - return endpoint; + return ESP_OK; } } /* on_off_switch */ @@ -325,16 +354,21 @@ uint8_t get_device_type_version() endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) { endpoint_t *endpoint = endpoint::create(node, flags, priv_data); - return add(endpoint, config); + add(endpoint, config); + return endpoint; } -endpoint_t *add(endpoint_t *endpoint, config_t *config) +esp_err_t add(endpoint_t *endpoint, config_t *config) { if (!endpoint) { ESP_LOGE(TAG, "Endpoint cannot be NULL"); - return NULL; + return ESP_ERR_INVALID_ARG; + } + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err); + return err; } - add_device_type(endpoint, get_device_type_id(), get_device_type_version()); descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER); identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER | CLUSTER_FLAG_CLIENT); @@ -342,7 +376,7 @@ endpoint_t *add(endpoint_t *endpoint, config_t *config) on_off::create(endpoint, NULL, CLUSTER_FLAG_CLIENT, ESP_MATTER_NONE_FEATURE_ID); level_control::create(endpoint, NULL, CLUSTER_FLAG_CLIENT, ESP_MATTER_NONE_FEATURE_ID); - return endpoint; + return ESP_OK; } } /* dimmer_switch */ @@ -361,16 +395,21 @@ uint8_t get_device_type_version() endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) { endpoint_t *endpoint = endpoint::create(node, flags, priv_data); - return add(endpoint, config); + add(endpoint, config); + return endpoint; } -endpoint_t *add(endpoint_t *endpoint, config_t *config) +esp_err_t add(endpoint_t *endpoint, config_t *config) { if (!endpoint) { ESP_LOGE(TAG, "Endpoint cannot be NULL"); - return NULL; + return ESP_ERR_INVALID_ARG; + } + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err); + return err; } - add_device_type(endpoint, get_device_type_id(), get_device_type_version()); descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER); identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER | CLUSTER_FLAG_CLIENT); @@ -379,7 +418,7 @@ endpoint_t *add(endpoint_t *endpoint, config_t *config) level_control::create(endpoint, NULL, CLUSTER_FLAG_CLIENT, ESP_MATTER_NONE_FEATURE_ID); color_control::create(endpoint, NULL, CLUSTER_FLAG_CLIENT, ESP_MATTER_NONE_FEATURE_ID); - return endpoint; + return ESP_OK; } } /* color_dimmer_switch */ @@ -397,22 +436,27 @@ uint8_t get_device_type_version() endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) { endpoint_t *endpoint = endpoint::create(node, flags, priv_data); - return add(endpoint, config); + add(endpoint, config); + return endpoint; } -endpoint_t *add(endpoint_t *endpoint, config_t *config) +esp_err_t add(endpoint_t *endpoint, config_t *config) { if (!endpoint) { ESP_LOGE(TAG, "Endpoint cannot be NULL"); - return NULL; + return ESP_ERR_INVALID_ARG; + } + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err); + return err; } - add_device_type(endpoint, get_device_type_id(), get_device_type_version()); descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER); identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER); switch_cluster::create(endpoint, &(config->switch_cluster), CLUSTER_FLAG_SERVER); - return endpoint; + return ESP_OK; } } /* color_dimmer_switch */ @@ -430,16 +474,21 @@ uint8_t get_device_type_version() endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) { endpoint_t *endpoint = endpoint::create(node, flags, priv_data); - return add(endpoint, config); + add(endpoint, config); + return endpoint; } -endpoint_t *add(endpoint_t *endpoint, config_t *config) +esp_err_t add(endpoint_t *endpoint, config_t *config) { if (!endpoint) { ESP_LOGE(TAG, "Endpoint cannot be NULL"); - return NULL; + return ESP_ERR_INVALID_ARG; + } + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err); + return err; } - add_device_type(endpoint, get_device_type_id(), get_device_type_version()); descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER); cluster_t *identify_cluster = identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER); @@ -448,7 +497,7 @@ endpoint_t *add(endpoint_t *endpoint, config_t *config) scenes::create(endpoint, &(config->scenes), CLUSTER_FLAG_SERVER); on_off::create(endpoint, &(config->on_off), CLUSTER_FLAG_SERVER, on_off::feature::lighting::get_id()); - return endpoint; + return ESP_OK; } } /* on_off_plugin_unit */ @@ -466,16 +515,21 @@ uint8_t get_device_type_version() endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) { endpoint_t *endpoint = endpoint::create(node, flags, priv_data); - return add(endpoint, config); + add(endpoint, config); + return endpoint; } -endpoint_t *add(endpoint_t *endpoint, config_t *config) +esp_err_t add(endpoint_t *endpoint, config_t *config) { if (!endpoint) { ESP_LOGE(TAG, "Endpoint cannot be NULL"); - return NULL; + return ESP_ERR_INVALID_ARG; + } + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err); + return err; } - add_device_type(endpoint, get_device_type_id(), get_device_type_version()); descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER); cluster_t *identify_cluster = identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER); @@ -486,7 +540,7 @@ endpoint_t *add(endpoint_t *endpoint, config_t *config) level_control::create(endpoint, &(config->level_control), CLUSTER_FLAG_SERVER, level_control::feature::on_off::get_id() | level_control::feature::lighting::get_id()); - return endpoint; + return ESP_OK; } } /* dimmable_plugin_unit */ @@ -504,23 +558,28 @@ uint8_t get_device_type_version() endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) { endpoint_t *endpoint = endpoint::create(node, flags, priv_data); - return add(endpoint, config); + add(endpoint, config); + return endpoint; } -endpoint_t *add(endpoint_t *endpoint, config_t *config) +esp_err_t add(endpoint_t *endpoint, config_t *config) { if (!endpoint) { ESP_LOGE(TAG, "Endpoint cannot be NULL"); - return NULL; + return ESP_ERR_INVALID_ARG; + } + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err); + return err; } - add_device_type(endpoint, get_device_type_id(), get_device_type_version()); descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER); identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER); groups::create(endpoint, &(config->groups), CLUSTER_FLAG_SERVER); fan_control::create(endpoint, &(config->fan_control), CLUSTER_FLAG_SERVER); - return endpoint; + return ESP_OK; } } /* fan */ @@ -538,16 +597,21 @@ uint8_t get_device_type_version() endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) { endpoint_t *endpoint = endpoint::create(node, flags, priv_data); - return add(endpoint, config); + add(endpoint, config); + return endpoint; } -endpoint_t *add(endpoint_t *endpoint, config_t *config) +esp_err_t add(endpoint_t *endpoint, config_t *config) { if (!endpoint) { ESP_LOGE(TAG, "Endpoint cannot be NULL"); - return NULL; + return ESP_ERR_INVALID_ARG; + } + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err); + return err; } - add_device_type(endpoint, get_device_type_id(), get_device_type_version()); descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER); identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER); @@ -555,7 +619,7 @@ endpoint_t *add(endpoint_t *endpoint, config_t *config) cluster::thermostat::create(endpoint, &(config->thermostat), CLUSTER_FLAG_SERVER, cluster::thermostat::feature::cooling::get_id() | cluster::thermostat::feature::heating::get_id()); - return endpoint; + return ESP_OK; } } /* thermostat */ @@ -573,20 +637,25 @@ uint8_t get_device_type_version() endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) { endpoint_t *endpoint = endpoint::create(node, flags, priv_data); - return add(endpoint, config); + add(endpoint, config); + return endpoint; } -endpoint_t *add(endpoint_t *endpoint, config_t *config) +esp_err_t add(endpoint_t *endpoint, config_t *config) { if (!endpoint) { ESP_LOGE(TAG, "Endpoint cannot be NULL"); - return NULL; + return ESP_ERR_INVALID_ARG; + } + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err); + return err; } - add_device_type(endpoint, get_device_type_id(), get_device_type_version()); descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER); - return endpoint; + return ESP_OK; } } /* aggregator */ @@ -605,28 +674,33 @@ endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_dat { // bridged node endpoints are always deletable endpoint_t *endpoint = endpoint::create(node, flags | ENDPOINT_FLAG_DESTROYABLE, priv_data); - return add(endpoint, config); + add(endpoint, config); + return endpoint; } -endpoint_t *add(endpoint_t *endpoint, config_t *config) +esp_err_t add(endpoint_t *endpoint, config_t *config) { if (!endpoint) { ESP_LOGE(TAG, "Endpoint cannot be NULL"); - return NULL; + return ESP_ERR_INVALID_ARG; + } + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err); + return err; } - - add_device_type(endpoint, get_device_type_id(), get_device_type_version()); descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER); bridged_device_basic_information::create(endpoint, &(config->bridged_device_basic_information), CLUSTER_FLAG_SERVER); - return endpoint; + return ESP_OK; } endpoint_t *resume(node_t *node, config_t *config, uint8_t flags, uint16_t endpoint_id, void *priv_data) { endpoint_t *endpoint = endpoint::resume(node, flags | ENDPOINT_FLAG_DESTROYABLE, endpoint_id, priv_data); - return add(endpoint, config); + add(endpoint, config); + return endpoint; } } /* bridged_node */ @@ -644,23 +718,27 @@ uint8_t get_device_type_version() endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) { endpoint_t *endpoint = endpoint::create(node, flags, priv_data); - return add(endpoint, config); + add(endpoint, config); + return endpoint; } -endpoint_t *add(endpoint_t *endpoint, config_t *config) +esp_err_t add(endpoint_t *endpoint, config_t *config) { if (!endpoint) { ESP_LOGE(TAG, "Endpoint cannot be NULL"); - return NULL; + return ESP_ERR_INVALID_ARG; + } + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err); + return err; } - - add_device_type(endpoint, get_device_type_id(), get_device_type_version()); descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER); identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER); cluster::door_lock::create(endpoint, &(config->door_lock), CLUSTER_FLAG_SERVER); - return endpoint; + return ESP_OK; } } /* door_lock */ @@ -678,17 +756,21 @@ uint8_t get_device_type_version() endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void * priv_data) { endpoint_t *endpoint = endpoint::create(node, flags, priv_data); - return add(endpoint, config); + add(endpoint, config); + return endpoint; } -endpoint_t *add(endpoint_t *endpoint, config_t *config) +esp_err_t add(endpoint_t *endpoint, config_t *config) { if (!endpoint) { ESP_LOGE(TAG, "Endpoint cannot be NULL"); - return NULL; + return ESP_ERR_INVALID_ARG; + } + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err); + return err; } - - add_device_type(endpoint, get_device_type_id(), get_device_type_version()); descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER); identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER); @@ -696,7 +778,7 @@ endpoint_t *add(endpoint_t *endpoint, config_t *config) scenes::create(endpoint, &(config->scenes), CLUSTER_FLAG_SERVER); window_covering::create(endpoint, &(config->window_covering), CLUSTER_FLAG_SERVER, ESP_MATTER_NONE_FEATURE_ID); - return endpoint; + return ESP_OK; } } /* window_covering */ @@ -714,22 +796,27 @@ uint8_t get_device_type_version() endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) { endpoint_t *endpoint = endpoint::create(node, flags, priv_data); - return add(endpoint, config); + add(endpoint, config); + return endpoint; } -endpoint_t *add(endpoint_t *endpoint, config_t *config) +esp_err_t add(endpoint_t *endpoint, config_t *config) { if (!endpoint) { ESP_LOGE(TAG, "Endpoint cannot be NULL"); - return NULL; + return ESP_ERR_INVALID_ARG; + } + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err); + return err; } - add_device_type(endpoint, get_device_type_id(), get_device_type_version()); descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER); identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER); temperature_measurement::create(endpoint, &(config->temperature_measurement), CLUSTER_FLAG_SERVER); - return endpoint; + return ESP_OK; } } /* temperature_sensor */ @@ -747,22 +834,27 @@ uint8_t get_device_type_version() endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) { endpoint_t *endpoint = endpoint::create(node, flags, priv_data); - return add(endpoint, config); + add(endpoint, config); + return endpoint; } -endpoint_t *add(endpoint_t *endpoint, config_t *config) +esp_err_t add(endpoint_t *endpoint, config_t *config) { if (!endpoint) { ESP_LOGE(TAG, "Endpoint cannot be NULL"); - return NULL; + return ESP_ERR_INVALID_ARG; + } + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err); + return err; } - add_device_type(endpoint, get_device_type_id(), get_device_type_version()); descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER); identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER); relative_humidity_measurement::create(endpoint, &(config->relative_humidity_measurement), CLUSTER_FLAG_SERVER); - return endpoint; + return ESP_OK; } } /* humidity_sensor */ @@ -780,22 +872,27 @@ uint8_t get_device_type_version() endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) { endpoint_t *endpoint = endpoint::create(node, flags, priv_data); - return add(endpoint, config); + add(endpoint, config); + return endpoint; } -endpoint_t *add(endpoint_t *endpoint, config_t *config) +esp_err_t add(endpoint_t *endpoint, config_t *config) { if (!endpoint) { ESP_LOGE(TAG, "Endpoint cannot be NULL"); - return NULL; + return ESP_ERR_INVALID_ARG; + } + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err); + return err; } - add_device_type(endpoint, get_device_type_id(), get_device_type_version()); descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER); identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER); occupancy_sensing::create(endpoint, &(config->occupancy_sensing), CLUSTER_FLAG_SERVER); - return endpoint; + return ESP_OK; } } /* occupancy_sensor */ @@ -813,22 +910,27 @@ uint8_t get_device_type_version() endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) { endpoint_t *endpoint = endpoint::create(node, flags, priv_data); - return add(endpoint, config); + add(endpoint, config); + return endpoint; } -endpoint_t *add(endpoint_t *endpoint, config_t *config) +esp_err_t add(endpoint_t *endpoint, config_t *config) { if (!endpoint) { ESP_LOGE(TAG, "Endpoint cannot be NULL"); - return NULL; + return ESP_ERR_INVALID_ARG; + } + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err); + return err; } - add_device_type(endpoint, get_device_type_id(), get_device_type_version()); descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER); identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER); boolean_state::create(endpoint, &(config->boolean_state), CLUSTER_FLAG_SERVER); - return endpoint; + return ESP_OK; } } /* contact_sensor */ @@ -846,22 +948,27 @@ uint8_t get_device_type_version() endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) { endpoint_t *endpoint = endpoint::create(node, flags, priv_data); - return add(endpoint, config); + add(endpoint, config); + return endpoint; } -endpoint_t *add(endpoint_t *endpoint, config_t *config) +esp_err_t add(endpoint_t *endpoint, config_t *config) { if (!endpoint) { ESP_LOGE(TAG, "Endpoint cannot be NULL"); - return NULL; + return ESP_ERR_INVALID_ARG; + } + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err); + return err; } - add_device_type(endpoint, get_device_type_id(), get_device_type_version()); descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER); identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER); illuminance_measurement::create(endpoint, &(config->illuminance_measurement), CLUSTER_FLAG_SERVER); - return endpoint; + return ESP_OK; } } /* light_sensor */ @@ -879,22 +986,27 @@ uint8_t get_device_type_version() endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) { endpoint_t *endpoint = endpoint::create(node, flags, priv_data); - return add(endpoint, config); + add(endpoint, config); + return endpoint; } -endpoint_t *add(endpoint_t *endpoint, config_t *config) +esp_err_t add(endpoint_t *endpoint, config_t *config) { if (!endpoint) { ESP_LOGE(TAG, "Endpoint cannot be NULL"); - return NULL; + return ESP_ERR_INVALID_ARG; + } + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err); + return err; } - add_device_type(endpoint, get_device_type_id(), get_device_type_version()); descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER); identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER); pressure_measurement::create(endpoint, &(config->pressure_measurement), CLUSTER_FLAG_SERVER); - return endpoint; + return ESP_OK; } } /* pressure_sensor */ @@ -912,22 +1024,27 @@ uint8_t get_device_type_version() endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) { endpoint_t *endpoint = endpoint::create(node, flags, priv_data); - return add(endpoint, config); + add(endpoint, config); + return endpoint; } -endpoint_t *add(endpoint_t *endpoint, config_t *config) +esp_err_t add(endpoint_t *endpoint, config_t *config) { if (!endpoint) { ESP_LOGE(TAG, "Endpoint cannot be NULL"); - return NULL; + return ESP_ERR_INVALID_ARG; + } + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err); + return err; } - add_device_type(endpoint, get_device_type_id(), get_device_type_version()); descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER); identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER); flow_measurement::create(endpoint, &(config->flow_measurement), CLUSTER_FLAG_SERVER); - return endpoint; + return ESP_OK; } } /* flow_sensor */ @@ -946,23 +1063,28 @@ uint8_t get_device_type_version() endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) { endpoint_t *endpoint = endpoint::create(node, flags, priv_data); - return add(endpoint, config); + add(endpoint, config); + return endpoint; } -endpoint_t *add(endpoint_t *endpoint, config_t *config) +esp_err_t add(endpoint_t *endpoint, config_t *config) { if (!endpoint) { - ESP_LOGE(TAG, "Could not create endpoint"); - return NULL; + ESP_LOGE(TAG, "Endpoint cannot be NULL"); + return ESP_ERR_INVALID_ARG; + } + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err); + return err; } - add_device_type(endpoint, get_device_type_id(), get_device_type_version()); identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER); descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER); on_off::create(endpoint, &(config->on_off), CLUSTER_FLAG_SERVER, ESP_MATTER_NONE_FEATURE_ID); pump_configuration_and_control::create(endpoint, &(config->pump_configuration_and_control), CLUSTER_FLAG_SERVER); - return endpoint; + return ESP_OK; } } /** pump **/ @@ -980,33 +1102,32 @@ uint8_t get_device_type_version() endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) { endpoint_t *endpoint = endpoint::create(node, flags, priv_data); - if (endpoint) { - return add(endpoint, config); - } + add(endpoint, config); return endpoint; } -endpoint_t *add(endpoint_t *endpoint, config_t *config) +esp_err_t add(endpoint_t *endpoint, config_t *config) { if (!endpoint) { - ESP_LOGE(TAG, "Could not create endpoint"); - return NULL; - } + ESP_LOGE(TAG, "Endpoint cannot be NULL"); + return ESP_ERR_INVALID_ARG; + } esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); if (err != ESP_OK) { - ESP_LOGE(TAG, "Failed to add device type: err: %d", err); + ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err); + return err; } cluster_t *cluster = descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER); if (!cluster) { - return NULL; + return ESP_ERR_INVALID_STATE; } cluster = mode_select::create(endpoint, &(config->mode_select), CLUSTER_FLAG_SERVER, ESP_MATTER_NONE_FEATURE_ID); if (!cluster) { - return NULL; + return ESP_ERR_INVALID_STATE; } - return endpoint; + return ESP_OK; } } /** mode_select_device **/ @@ -1026,20 +1147,21 @@ uint8_t get_device_type_version() endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) { endpoint_t *endpoint = endpoint::create(node, flags, priv_data); - if (endpoint) { - return add(endpoint, config); - } + add(endpoint, config); return endpoint; } -endpoint_t *add(endpoint_t *endpoint, config_t *config) +esp_err_t add(endpoint_t *endpoint, config_t *config) { if (!endpoint) { - ESP_LOGE(TAG, "Could not create endpoint"); - return NULL; + ESP_LOGE(TAG, "Endpoint cannot be NULL"); + return ESP_ERR_INVALID_ARG; + } + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err); + return err; } - - add_device_type(endpoint, get_device_type_id(), get_device_type_version()); descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER); identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER); @@ -1047,7 +1169,7 @@ endpoint_t *add(endpoint_t *endpoint, config_t *config) cluster::thermostat::create(endpoint, &(config->thermostat), CLUSTER_FLAG_SERVER, cluster::thermostat::feature::cooling::get_id() | cluster::thermostat::feature::heating::get_id()); - return endpoint; + return ESP_OK; } } /** room_air_conditioner **/ @@ -1067,21 +1189,26 @@ uint8_t get_device_type_version() endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) { endpoint_t *endpoint = endpoint::create(node, flags, priv_data); - return add(endpoint, config); + add(endpoint, config); + return endpoint; } -endpoint_t *add(endpoint_t *endpoint, config_t *config) +esp_err_t add(endpoint_t *endpoint, config_t *config) { if (!endpoint) { - ESP_LOGE(TAG, "Could not create endpoint"); - return NULL; + ESP_LOGE(TAG, "Endpoint cannot be NULL"); + return ESP_ERR_INVALID_ARG; + } + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err); + return err; } - add_device_type(endpoint, get_device_type_id(), get_device_type_version()); descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER); temperature_control::create(endpoint, &(config->temperature_control), CLUSTER_FLAG_SERVER, ESP_MATTER_NONE_FEATURE_ID); - return endpoint; + return ESP_OK; } } /** temperature_controlled_cabinet**/ @@ -1100,20 +1227,25 @@ uint8_t get_device_type_version() endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) { endpoint_t *endpoint = endpoint::create(node, flags, priv_data); - return add(endpoint, config); + add(endpoint, config); + return endpoint; } -endpoint_t *add(endpoint_t *endpoint, config_t *config) +esp_err_t add(endpoint_t *endpoint, config_t *config) { if (!endpoint) { - ESP_LOGE(TAG, "Could not create endpoint"); - return NULL; + ESP_LOGE(TAG, "Endpoint cannot be NULL"); + return ESP_ERR_INVALID_ARG; + } + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err); + return err; } - add_device_type(endpoint, get_device_type_id(), get_device_type_version()); descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER); - return endpoint; + return ESP_OK; } } /** refrigerator **/ diff --git a/components/esp_matter/esp_matter_endpoint.h b/components/esp_matter/esp_matter_endpoint.h index fa6ed11e3..09313c649 100644 --- a/components/esp_matter/esp_matter_endpoint.h +++ b/components/esp_matter/esp_matter_endpoint.h @@ -115,7 +115,7 @@ typedef struct config { uint32_t get_device_type_id(); uint8_t get_device_type_version(); endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data); -endpoint_t *add(endpoint_t *endpoint, config_t *config); +esp_err_t add(endpoint_t *endpoint, config_t *config); } /* root_node */ namespace power_source_device{ @@ -127,7 +127,7 @@ typedef struct config { uint32_t get_device_type_id(); uint8_t get_device_type_version(); endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data); -endpoint_t *add(endpoint_t *endpoint, config_t *config); +esp_err_t add(endpoint_t *endpoint, config_t *config); } /* power_source_device */ namespace on_off_light { @@ -142,7 +142,7 @@ typedef struct config { uint32_t get_device_type_id(); uint8_t get_device_type_version(); endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data); -endpoint_t *add(endpoint_t *endpoint, config_t *config); +esp_err_t add(endpoint_t *endpoint, config_t *config); } /* on_off_light */ namespace dimmable_light { @@ -158,7 +158,7 @@ typedef struct config { uint32_t get_device_type_id(); uint8_t get_device_type_version(); endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data); -endpoint_t *add(endpoint_t *endpoint, config_t *config); +esp_err_t add(endpoint_t *endpoint, config_t *config); } /* dimmable_light */ namespace color_temperature_light { @@ -175,7 +175,7 @@ typedef struct config { uint32_t get_device_type_id(); uint8_t get_device_type_version(); endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data); -endpoint_t *add(endpoint_t *endpoint, config_t *config); +esp_err_t add(endpoint_t *endpoint, config_t *config); } /* color_temperature_light */ namespace extended_color_light { @@ -192,7 +192,7 @@ typedef struct config { uint32_t get_device_type_id(); uint8_t get_device_type_version(); endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data); -endpoint_t *add(endpoint_t *endpoint, config_t *config); +esp_err_t add(endpoint_t *endpoint, config_t *config); } /* extended_color_light */ namespace on_off_switch { @@ -205,7 +205,7 @@ typedef struct config { uint32_t get_device_type_id(); uint8_t get_device_type_version(); endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data); -endpoint_t *add(endpoint_t *endpoint, config_t *config); +esp_err_t add(endpoint_t *endpoint, config_t *config); } /* on_off_switch */ namespace dimmer_switch { @@ -218,7 +218,7 @@ typedef struct config { uint32_t get_device_type_id(); uint8_t get_device_type_version(); endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data); -endpoint_t *add(endpoint_t *endpoint, config_t *config); +esp_err_t add(endpoint_t *endpoint, config_t *config); } /* dimmer_switch */ namespace color_dimmer_switch { @@ -231,7 +231,7 @@ typedef struct config { uint32_t get_device_type_id(); uint8_t get_device_type_version(); endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data); -endpoint_t *add(endpoint_t *endpoint, config_t *config); +esp_err_t add(endpoint_t *endpoint, config_t *config); } /* color_dimmer_switch */ namespace generic_switch { @@ -244,7 +244,7 @@ typedef struct config { uint32_t get_device_type_id(); uint8_t get_device_type_version(); endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data); -endpoint_t *add(endpoint_t *endpoint, config_t *config); +esp_err_t add(endpoint_t *endpoint, config_t *config); } /* generic_switch */ namespace on_off_plugin_unit { @@ -259,7 +259,7 @@ typedef struct config { uint32_t get_device_type_id(); uint8_t get_device_type_version(); endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data); -endpoint_t *add(endpoint_t *endpoint, config_t *config); +esp_err_t add(endpoint_t *endpoint, config_t *config); } /* on_off_plugin_unit */ namespace dimmable_plugin_unit { @@ -275,7 +275,7 @@ typedef struct config { uint32_t get_device_type_id(); uint8_t get_device_type_version(); endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data); -endpoint_t *add(endpoint_t *endpoint, config_t *config); +esp_err_t add(endpoint_t *endpoint, config_t *config); } /* dimmable_plugin_unit */ namespace fan { @@ -289,7 +289,7 @@ typedef struct config { uint32_t get_device_type_id(); uint8_t get_device_type_version(); endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data); -endpoint_t *add(endpoint_t *endpoint, config_t *config); +esp_err_t add(endpoint_t *endpoint, config_t *config); } /* fan */ namespace thermostat { @@ -304,7 +304,7 @@ typedef struct config { uint32_t get_device_type_id(); uint8_t get_device_type_version(); endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data); -endpoint_t *add(endpoint_t *endpoint, config_t *config); +esp_err_t add(endpoint_t *endpoint, config_t *config); } /* thermostat */ namespace aggregator { @@ -315,7 +315,7 @@ typedef struct config { uint32_t get_device_type_id(); uint8_t get_device_type_version(); endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data); -endpoint_t *add(endpoint_t *endpoint, config_t *config); +esp_err_t add(endpoint_t *endpoint, config_t *config); } /* aggregator */ namespace bridged_node { @@ -327,7 +327,7 @@ typedef struct config { uint32_t get_device_type_id(); uint8_t get_device_type_version(); endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data); -endpoint_t *add(endpoint_t *endpoint, config_t *config); +esp_err_t add(endpoint_t *endpoint, config_t *config); endpoint_t *resume(node_t *node, config_t *config, uint8_t flags, uint16_t endpoint_id, void *priv_data); } /* bridged_node */ @@ -341,7 +341,7 @@ typedef struct config { uint32_t get_device_type_id(); uint8_t get_device_type_version(); endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data); -endpoint_t *add(endpoint_t *endpoint, config_t *config); +esp_err_t add(endpoint_t *endpoint, config_t *config); } /* door_lock */ namespace window_covering_device { @@ -357,7 +357,7 @@ typedef struct config { uint32_t get_device_type_id(); uint8_t get_device_type_version(); endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data); -endpoint_t *add(endpoint_t *endpoint, config_t *config); +esp_err_t add(endpoint_t *endpoint, config_t *config); } /* window_covering */ namespace temperature_sensor { @@ -370,7 +370,7 @@ typedef struct config { uint32_t get_device_type_id(); uint8_t get_device_type_version(); endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data); -endpoint_t *add(endpoint_t *endpoint, config_t *config); +esp_err_t add(endpoint_t *endpoint, config_t *config); } /* temperature_sensor */ namespace humidity_sensor { @@ -383,7 +383,7 @@ typedef struct config { uint32_t get_device_type_id(); uint8_t get_device_type_version(); endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data); -endpoint_t *add(endpoint_t *endpoint, config_t *config); +esp_err_t add(endpoint_t *endpoint, config_t *config); } /* humidity_sensor */ namespace occupancy_sensor { @@ -396,7 +396,7 @@ typedef struct config { uint32_t get_device_type_id(); uint8_t get_device_type_version(); endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data); -endpoint_t *add(endpoint_t *endpoint, config_t *config); +esp_err_t add(endpoint_t *endpoint, config_t *config); } /* occupancy_sensor */ namespace contact_sensor { @@ -409,7 +409,7 @@ typedef struct config { uint32_t get_device_type_id(); uint8_t get_device_type_version(); endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data); -endpoint_t *add(endpoint_t *endpoint, config_t *config); +esp_err_t add(endpoint_t *endpoint, config_t *config); } /* contact_sensor */ namespace light_sensor { @@ -422,7 +422,7 @@ typedef struct config { uint32_t get_device_type_id(); uint8_t get_device_type_version(); endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data); -endpoint_t *add(endpoint_t *endpoint, config_t *config); +esp_err_t add(endpoint_t *endpoint, config_t *config); } /* light_sensor */ namespace pressure_sensor { @@ -435,7 +435,7 @@ typedef struct config { uint32_t get_device_type_id(); uint8_t get_device_type_version(); endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data); -endpoint_t *add(endpoint_t *endpoint, config_t *config); +esp_err_t add(endpoint_t *endpoint, config_t *config); } /* pressure_sensor */ namespace flow_sensor { @@ -448,7 +448,7 @@ typedef struct config { uint32_t get_device_type_id(); uint8_t get_device_type_version(); endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data); -endpoint_t *add(endpoint_t *endpoint, config_t *config); +esp_err_t add(endpoint_t *endpoint, config_t *config); } /* flow_sensor */ namespace pump{ @@ -467,7 +467,7 @@ typedef struct config { uint32_t get_device_type_id(); uint8_t get_device_type_version(); endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data); -endpoint_t *add(endpoint_t *endpoint, config_t *config); +esp_err_t add(endpoint_t *endpoint, config_t *config); } /** pump **/ namespace mode_select_device { @@ -479,7 +479,7 @@ typedef struct config { uint32_t get_device_type_id(); uint8_t get_device_type_version(); endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data); -endpoint_t *add(endpoint_t *endpoint, config_t *config); +esp_err_t add(endpoint_t *endpoint, config_t *config); } /** mode_select_device **/ namespace room_air_conditioner{ @@ -493,7 +493,7 @@ typedef struct config { uint32_t get_device_type_id(); uint8_t get_device_type_version(); endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data); -endpoint_t *add(endpoint_t *endpoint, config_t *config); +esp_err_t add(endpoint_t *endpoint, config_t *config); } /** room air conditioner **/ namespace temperature_controlled_cabinet{ @@ -505,7 +505,7 @@ typedef struct config { uint32_t get_device_type_id(); uint8_t get_device_type_version(); endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data); -endpoint_t *add(endpoint_t *endpoint, config_t *config); +esp_err_t add(endpoint_t *endpoint, config_t *config); } /** temperature_controlled_cabinet **/ namespace refrigerator{ @@ -516,7 +516,7 @@ typedef struct config { uint32_t get_device_type_id(); uint8_t get_device_type_version(); endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data); -endpoint_t *add(endpoint_t *endpoint, config_t *config); +esp_err_t add(endpoint_t *endpoint, config_t *config); } /** refrigerator **/ } /* endpoint */ diff --git a/components/esp_matter_bridge/esp_matter_bridge.cpp b/components/esp_matter_bridge/esp_matter_bridge.cpp index 576a3580f..34636dcb9 100644 --- a/components/esp_matter_bridge/esp_matter_bridge.cpp +++ b/components/esp_matter_bridge/esp_matter_bridge.cpp @@ -182,31 +182,51 @@ esp_err_t set_device_type(device_t *bridged_device, uint32_t device_type_id) ESP_LOGE(TAG, "bridged_device cannot be NULL"); return ESP_ERR_INVALID_ARG; } + esp_err_t err = ESP_OK; switch (device_type_id) { case ESP_MATTER_ON_OFF_LIGHT_DEVICE_TYPE_ID: { on_off_light::config_t on_off_light_conf; - bridged_device->endpoint = on_off_light::add(bridged_device->endpoint, &on_off_light_conf); + err = on_off_light::add(bridged_device->endpoint, &on_off_light_conf); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type"); + return err; + } break; } case ESP_MATTER_DIMMABLE_LIGHT_DEVICE_TYPE_ID: { dimmable_light::config_t dimmable_light_conf; - bridged_device->endpoint = dimmable_light::add(bridged_device->endpoint, &dimmable_light_conf); + err = dimmable_light::add(bridged_device->endpoint, &dimmable_light_conf); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type"); + return err; + } break; } case ESP_MATTER_COLOR_TEMPERATURE_LIGHT_DEVICE_TYPE_ID: { color_temperature_light::config_t color_temperature_light_conf; - bridged_device->endpoint = - color_temperature_light::add(bridged_device->endpoint, &color_temperature_light_conf); + err = color_temperature_light::add(bridged_device->endpoint, &color_temperature_light_conf); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type"); + return err; + } break; } case ESP_MATTER_EXTENDED_COLOR_LIGHT_DEVICE_TYPE_ID: { extended_color_light::config_t extended_color_light_conf; - bridged_device->endpoint = extended_color_light::add(bridged_device->endpoint, &extended_color_light_conf); + err = extended_color_light::add(bridged_device->endpoint, &extended_color_light_conf); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type"); + return err; + } break; } case ESP_MATTER_ON_OFF_SWITCH_DEVICE_TYPE_ID: { on_off_switch::config_t switch_config; - bridged_device->endpoint = on_off_switch::add(bridged_device->endpoint, &switch_config); + err = on_off_switch::add(bridged_device->endpoint, &switch_config); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add device type"); + return err; + } break; } default: {