From d3a145a71345ae1a08276cef529c9e9452a3885b Mon Sep 17 00:00:00 2001 From: Rohit Jadhav Date: Fri, 2 Aug 2024 14:14:55 +0530 Subject: [PATCH] components/esp_matter: Add control bridge device type. Fixes https://github.com/espressif/esp-matter/issues/1029 --- SUPPORTED_DEVICE_TYPES.md | 1 + components/esp_matter/esp_matter_endpoint.cpp | 41 +++++++++++++++++++ components/esp_matter/esp_matter_endpoint.h | 15 +++++++ .../all_device_types_app/main/device_types.h | 2 + .../main/esp_matter_console_helpers.cpp | 7 +++- 5 files changed, 65 insertions(+), 1 deletion(-) diff --git a/SUPPORTED_DEVICE_TYPES.md b/SUPPORTED_DEVICE_TYPES.md index 9a99d0a0f..bbb7ff795 100644 --- a/SUPPORTED_DEVICE_TYPES.md +++ b/SUPPORTED_DEVICE_TYPES.md @@ -26,6 +26,7 @@ b. Switches 3. Color Dimmer Switch 4. Generic Switch 5. Pump Controller +6. Control Bridge c. Smart Plugs/Outlets 1. On/Off Plugin Unit diff --git a/components/esp_matter/esp_matter_endpoint.cpp b/components/esp_matter/esp_matter_endpoint.cpp index e22c5be70..4e469c0dd 100644 --- a/components/esp_matter/esp_matter_endpoint.cpp +++ b/components/esp_matter/esp_matter_endpoint.cpp @@ -701,6 +701,47 @@ esp_err_t add(endpoint_t *endpoint, config_t *config) } } /* aggregator */ +namespace control_bridge { +uint32_t get_device_type_id() +{ + return ESP_MATTER_CONTROL_BRIDGE_DEVICE_TYPE_ID; +} + +uint8_t get_device_type_version() +{ + return ESP_MATTER_CONTROL_BRIDGE_DEVICE_TYPE_VERSION; +} + +endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) +{ + endpoint_t * endpoint = common::create(node, config, flags, priv_data, add); + VerifyOrReturnError(endpoint != nullptr, NULL); + + cluster_t *binding_cluster = binding::create(endpoint, &(config->binding), CLUSTER_FLAG_SERVER); + VerifyOrReturnValue(binding_cluster != nullptr, NULL, ESP_LOGE(TAG, "Failed to create binding cluster")); + + return endpoint; +} + +esp_err_t add(endpoint_t *endpoint, config_t *config) +{ + VerifyOrReturnError(endpoint != nullptr, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Endpoint cannot be NULL")); + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed add device type id:%" PRIu32 ", err: %d", get_device_type_id(), err); + return err; + } + + identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER | CLUSTER_FLAG_CLIENT); + groups::create(endpoint, NULL, CLUSTER_FLAG_CLIENT); + scenes_management::create(endpoint, NULL, CLUSTER_FLAG_CLIENT); + 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); + color_control::create(endpoint, NULL, CLUSTER_FLAG_CLIENT, ESP_MATTER_NONE_FEATURE_ID); + return ESP_OK; +} +} /* control_bridge */ + namespace air_quality_sensor { uint32_t get_device_type_id() { diff --git a/components/esp_matter/esp_matter_endpoint.h b/components/esp_matter/esp_matter_endpoint.h index 651282052..43b972a91 100644 --- a/components/esp_matter/esp_matter_endpoint.h +++ b/components/esp_matter/esp_matter_endpoint.h @@ -31,6 +31,8 @@ #define ESP_MATTER_AGGREGATOR_DEVICE_TYPE_VERSION 1 #define ESP_MATTER_BRIDGED_NODE_DEVICE_TYPE_ID 0x0013 #define ESP_MATTER_BRIDGED_NODE_DEVICE_TYPE_VERSION 2 +#define ESP_MATTER_CONTROL_BRIDGE_DEVICE_TYPE_ID 0x0840 +#define ESP_MATTER_CONTROL_BRIDGE_DEVICE_TYPE_VERSION 3 #define ESP_MATTER_ON_OFF_LIGHT_DEVICE_TYPE_ID 0x0100 #define ESP_MATTER_ON_OFF_LIGHT_DEVICE_TYPE_VERSION 3 @@ -469,6 +471,19 @@ 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 */ +namespace control_bridge { +typedef struct config { + cluster::descriptor::config_t descriptor; + cluster::identify::config_t identify; + cluster::binding::config_t binding; +} config_t; + +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); +esp_err_t add(endpoint_t *endpoint, config_t *config); +} /* control_bridge */ + namespace door_lock { typedef struct config { cluster::descriptor::config_t descriptor; diff --git a/examples/all_device_types_app/main/device_types.h b/examples/all_device_types_app/main/device_types.h index 2e75cd1f6..5f2899805 100644 --- a/examples/all_device_types_app/main/device_types.h +++ b/examples/all_device_types_app/main/device_types.h @@ -17,6 +17,7 @@ enum device_type_enum { ESP_MATTER_THERMOSTAT, ESP_MATTER_AGGREGATOR, ESP_MATTER_BRIDGED_NODE, + ESP_MATTER_CONTROL_BRIDGE, ESP_MATTER_DOOR_LOCK, ESP_MATTER_WINDOW_COVERING_DEVICE, ESP_MATTER_TEMP_SENSOR, @@ -74,6 +75,7 @@ const device_type_name device_type_list[ESP_MATTER_DEVICE_TYPE_MAX] = { {"thermostat", ESP_MATTER_THERMOSTAT}, {"aggregator", ESP_MATTER_AGGREGATOR}, {"bridged_node", ESP_MATTER_BRIDGED_NODE}, + {"control_bridge", ESP_MATTER_CONTROL_BRIDGE}, {"door_lock", ESP_MATTER_DOOR_LOCK}, {"window_covering_device", ESP_MATTER_WINDOW_COVERING_DEVICE}, {"temperature_sensor", ESP_MATTER_TEMP_SENSOR}, diff --git a/examples/all_device_types_app/main/esp_matter_console_helpers.cpp b/examples/all_device_types_app/main/esp_matter_console_helpers.cpp index 07e1e581b..cb831e55d 100644 --- a/examples/all_device_types_app/main/esp_matter_console_helpers.cpp +++ b/examples/all_device_types_app/main/esp_matter_console_helpers.cpp @@ -255,7 +255,7 @@ int create(uint8_t device_type_index) } case ESP_MATTER_AGGREGATOR: { esp_matter::endpoint::aggregator::config_t aggregator_config; - endpoint = esp_matter::endpoint::aggregator::create(node, &aggregator_config, ENDPOINT_FLAG_NONE, NULL); + endpoint = esp_matter::endpoint::aggregator::create(node, &aggregator_config, ENDPOINT_FLAG_NONE, NULL); break; } case ESP_MATTER_BRIDGED_NODE: { @@ -263,6 +263,11 @@ int create(uint8_t device_type_index) endpoint = esp_matter::endpoint::bridged_node::create(node, &bridged_node_config, ENDPOINT_FLAG_NONE, NULL); break; } + case ESP_MATTER_CONTROL_BRIDGE: { + esp_matter::endpoint::control_bridge::config_t control_bridge_config; + endpoint = esp_matter::endpoint::control_bridge::create(node, &control_bridge_config, ENDPOINT_FLAG_NONE, NULL); + break; + } case ESP_MATTER_DOOR_LOCK: { esp_matter::endpoint::door_lock::config_t door_lock_config; endpoint = esp_matter::endpoint::door_lock::create(node, &door_lock_config, ENDPOINT_FLAG_NONE, NULL);