Merge branch 'feat/add-closure_control-cluster' into 'main'

Add Closure Control Cluster to esp-matter Data Model

See merge request app-frameworks/esp-matter!1326
This commit is contained in:
Hrishikesh Dhayagude
2025-12-04 20:55:49 +08:00
13 changed files with 442 additions and 0 deletions
@@ -4945,5 +4945,47 @@ attribute_t *create_enabled(cluster_t *cluster, bool value)
} /* chime */
namespace closure_control {
namespace attribute {
attribute_t *create_countdown_time(cluster_t *cluster, nullable<uint32_t> value)
{
return esp_matter::attribute::create(cluster, ClosureControl::Attributes::CountdownTime::Id,
ATTRIBUTE_FLAG_MANAGED_INTERNALLY | ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_uint32(value));
}
attribute_t *create_main_state(cluster_t *cluster, uint8_t value)
{
return esp_matter::attribute::create(cluster, ClosureControl::Attributes::MainState::Id,
ATTRIBUTE_FLAG_MANAGED_INTERNALLY, esp_matter_enum8(value));
}
attribute_t *create_current_error_list(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count)
{
return esp_matter::attribute::create(cluster, ClosureControl::Attributes::CurrentErrorList::Id,
ATTRIBUTE_FLAG_MANAGED_INTERNALLY, esp_matter_array(value, length, count));
}
attribute_t *create_overall_current_state(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count)
{
return esp_matter::attribute::create(cluster, ClosureControl::Attributes::OverallCurrentState::Id,
ATTRIBUTE_FLAG_MANAGED_INTERNALLY | ATTRIBUTE_FLAG_NULLABLE, esp_matter_array(value, length, count));
}
attribute_t *create_overall_target_state(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count)
{
return esp_matter::attribute::create(cluster, ClosureControl::Attributes::OverallTargetState::Id,
ATTRIBUTE_FLAG_MANAGED_INTERNALLY | ATTRIBUTE_FLAG_NULLABLE, esp_matter_array(value, length, count));
}
attribute_t *create_latch_control_modes(cluster_t *cluster, uint8_t value)
{
return esp_matter::attribute::create(cluster, ClosureControl::Attributes::LatchControlModes::Id,
ATTRIBUTE_FLAG_MANAGED_INTERNALLY, esp_matter_bitmap8(value));
}
} /* attribute */
} /* closure_control */
} /* cluster */
} /* esp_matter */
@@ -1279,5 +1279,17 @@ attribute_t *create_enabled(cluster_t *cluster, bool value);
} /* attribute */
} /* chime */
namespace closure_control {
namespace attribute {
attribute_t *create_countdown_time(cluster_t *cluster, nullable<uint32_t> value);
attribute_t *create_main_state(cluster_t *cluster, uint8_t value);
attribute_t *create_current_error_list(cluster_t *cluster, uint8_t * value, uint16_t length, uint16_t count);
attribute_t *create_overall_current_state(cluster_t *cluster, uint8_t * value, uint16_t length, uint16_t count);
attribute_t *create_overall_target_state(cluster_t *cluster, uint8_t * value, uint16_t length, uint16_t count);
attribute_t *create_latch_control_modes(cluster_t *cluster, uint8_t value);
} /* attribute */
} /* closure_control */
} /* cluster */
} /* esp_matter */
@@ -4081,5 +4081,88 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags)
} /* chime */
namespace closure_control {
const function_generic_t *function_list = NULL;
const int function_flags = CLUSTER_FLAG_NONE;
cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags)
{
cluster_t *cluster = esp_matter::cluster::create(endpoint, ClosureControl::Id, flags);
VerifyOrReturnValue(cluster, NULL, ESP_LOGE(TAG, "Could not create cluster. cluster_id: 0x%08" PRIX32, ClosureControl::Id));
if (flags & CLUSTER_FLAG_SERVER) {
if (config->delegate != nullptr) {
static const auto delegate_init_cb = ClosureControlDelegateInitCB;
set_delegate_and_init_callback(cluster, delegate_init_cb, config->delegate);
}
static const auto plugin_server_init_cb = CALL_ONCE(MatterClosureControlPluginServerInitCallback);
set_plugin_server_init_callback(cluster, plugin_server_init_cb);
add_function_list(cluster, function_list, function_flags);
VerifyOrReturnValue(config != NULL, ABORT_CLUSTER_CREATE(cluster));
/* Attributes managed internally */
global::attribute::create_feature_map(cluster, config->feature_flags);
attribute::create_main_state(cluster, 0);
attribute::create_current_error_list(cluster, NULL, 0, 0);
attribute::create_overall_current_state(cluster, NULL, 0, 0);
attribute::create_overall_target_state(cluster, NULL, 0, 0);
/* Attributes not managed internally */
global::attribute::create_cluster_revision(cluster, cluster_revision);
// check against O.a+ feature conformance
VALIDATE_FEATURES_AT_LEAST_ONE("Positioning,MotionLatching",
feature::positioning::get_id(), feature::motion_latching::get_id());
if (has(feature::positioning::get_id())) {
VerifyOrReturnValue(feature::positioning::add(cluster) == ESP_OK, ABORT_CLUSTER_CREATE(cluster));
if (has(feature::ventilation::get_id())) {
VerifyOrReturnValue(feature::ventilation::add(cluster) == ESP_OK, ABORT_CLUSTER_CREATE(cluster));
}
if (has(feature::pedestrian::get_id())) {
VerifyOrReturnValue(feature::pedestrian::add(cluster) == ESP_OK, ABORT_CLUSTER_CREATE(cluster));
}
if (has(feature::calibration::get_id())) {
VerifyOrReturnValue(feature::calibration::add(cluster) == ESP_OK, ABORT_CLUSTER_CREATE(cluster));
}
}
if (has(feature::motion_latching::get_id())) {
VerifyOrReturnValue(feature::motion_latching::add(cluster) == ESP_OK, ABORT_CLUSTER_CREATE(cluster));
}
if (has(feature::manually_operable::get_id())) {
VerifyOrReturnValue(feature::manually_operable::add(cluster) == ESP_OK, ABORT_CLUSTER_CREATE(cluster));
}
if (has(feature::instantaneous::get_id())) {
VerifyOrReturnValue(feature::instantaneous::add(cluster) == ESP_OK, ABORT_CLUSTER_CREATE(cluster));
}
if (has(feature::speed::get_id())) {
if (has(feature::positioning::get_id()) && !has(feature::instantaneous::get_id())) {
VerifyOrReturnValue(feature::speed::add(cluster) == ESP_OK, ABORT_CLUSTER_CREATE(cluster));
}
}
if (has(feature::protection::get_id())) {
VerifyOrReturnValue(feature::protection::add(cluster) == ESP_OK, ABORT_CLUSTER_CREATE(cluster));
}
command::create_move_to(cluster);
if (!has(feature::instantaneous::get_id())) {
command::create_stop(cluster);
}
/* Events */
event::create_operational_error(cluster);
event::create_secure_state_changed(cluster);
if (!has(feature::instantaneous::get_id())) {
event::create_movement_completed(cluster);
}
}
if (flags & CLUSTER_FLAG_CLIENT) {
create_default_binding_cluster(endpoint);
}
return cluster;
}
} /* closure_control */
} /* cluster */
} /* esp_matter */
@@ -1007,5 +1007,15 @@ typedef struct config {
cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags);
} /* chime */
namespace closure_control {
typedef struct config {
void *delegate;
uint32_t feature_flags;
config() : delegate(nullptr), feature_flags(0) {}
} config_t;
cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags);
} /* closure_control */
} /* cluster */
} /* esp_matter */
@@ -3013,5 +3013,28 @@ command_t *create_play_chime_sound(cluster_t *cluster)
} /* command */
} /* chime */
namespace closure_control {
namespace command {
command_t *create_stop(cluster_t *cluster)
{
return esp_matter::command::create(cluster, ClosureControl::Commands::Stop::Id,
COMMAND_FLAG_ACCEPTED, NULL);
}
command_t *create_move_to(cluster_t *cluster)
{
return esp_matter::command::create(cluster, ClosureControl::Commands::MoveTo::Id,
COMMAND_FLAG_ACCEPTED, NULL);
}
command_t *create_calibrate(cluster_t *cluster)
{
return esp_matter::command::create(cluster, ClosureControl::Commands::Calibrate::Id,
COMMAND_FLAG_ACCEPTED, NULL);
}
} /* command */
} /* closure_control */
} /* cluster */
} /* esp_matter */
@@ -552,5 +552,13 @@ command_t *create_play_chime_sound(cluster_t *cluster);
} /* command */
} /* chime */
namespace closure_control {
namespace command {
command_t *create_stop(cluster_t *cluster);
command_t *create_move_to(cluster_t *cluster);
command_t *create_calibrate(cluster_t *cluster);
} /* command */
} /* closure_control */
} /* cluster */
} /* esp_matter */
@@ -48,6 +48,7 @@
#include <app/clusters/ota-provider/CodegenIntegration.h>
#include <app/clusters/diagnostic-logs-server/diagnostic-logs-server.h>
#include <app/clusters/chime-server/chime-server.h>
#include <app/clusters/closure-control-server/closure-control-server.h>
#include <unordered_map>
using namespace chip::app::Clusters;
@@ -548,6 +549,16 @@ void ChimeDelegateInitCB(void *delegate, uint16_t endpoint_id)
chime_server->Init();
}
void ClosureControlDelegateInitCB(void *delegate, uint16_t endpoint_id)
{
VerifyOrReturn(delegate != nullptr);
ClosureControl::DelegateBase *closure_control_delegate = static_cast<ClosureControl::DelegateBase*>(delegate);
ClosureControl::MatterContext *matter_context = new ClosureControl::MatterContext(endpoint_id);
ClosureControl::ClusterLogic *cluster_logic = new ClosureControl::ClusterLogic(*closure_control_delegate, *matter_context);
ClosureControl::Interface *server_interface = new ClosureControl::Interface(endpoint_id, *cluster_logic);
server_interface->Init();
}
} // namespace delegate_cb
} // namespace cluster
} // namespace esp_matter
@@ -56,6 +56,7 @@ void ThermostatDelegateInitCB(void *delegate, uint16_t endpoint_id);
void OtaSoftwareUpdateProviderDelegateInitCB(void *delegate, uint16_t endpoint_id);
void DiagnosticLogsDelegateInitCB(void *delegate, uint16_t endpoint_id);
void ChimeDelegateInitCB(void *delegate, uint16_t endpoint_id);
void ClosureControlDelegateInitCB(void *delegate, uint16_t endpoint_id);
} // namespace delegate_cb
} // namespace cluster
@@ -842,5 +842,30 @@ event_t *create_occupancy_changed(cluster_t *cluster)
} // namespace event
} // namespace occupancy_sensing
namespace closure_control {
namespace event {
event_t *create_operational_error(cluster_t *cluster)
{
return esp_matter::event::create(cluster, ClosureControl::Events::OperationalError::Id);
}
event_t *create_movement_completed(cluster_t *cluster)
{
return esp_matter::event::create(cluster, ClosureControl::Events::MovementCompleted::Id);
}
event_t *create_engage_state_changed(cluster_t *cluster)
{
return esp_matter::event::create(cluster, ClosureControl::Events::EngageStateChanged::Id);
}
event_t *create_secure_state_changed(cluster_t *cluster)
{
return esp_matter::event::create(cluster, ClosureControl::Events::SecureStateChanged::Id);
}
} // namespace event
} // namespace closure_control
} // namespace cluster
} // namespace esp_matter
@@ -263,5 +263,14 @@ event_t *create_occupancy_changed(cluster_t *cluster);
} // namespace event
} // namespace occupancy_sensing
namespace closure_control {
namespace event {
event_t *create_operational_error(cluster_t *cluster);
event_t *create_movement_completed(cluster_t *cluster);
event_t *create_engage_state_changed(cluster_t *cluster);
event_t *create_secure_state_changed(cluster_t *cluster);
} // namespace event
} // namespace closure_control
} // namespace cluster
} // namespace esp_matter
@@ -4212,5 +4212,159 @@ namespace webrtc_transport_requestor {
}/*webrtc_transport_requestor*/
namespace closure_control {
namespace feature {
namespace positioning {
uint32_t get_id()
{
return static_cast<uint32_t>(ClosureControl::Feature::kPositioning);
}
esp_err_t add(cluster_t *cluster)
{
VerifyOrReturnError(cluster, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Cluster cannot be NULL"));
update_feature_map(cluster, get_id());
return ESP_OK;
}
} /* positioning */
namespace motion_latching {
uint32_t get_id()
{
return static_cast<uint32_t>(ClosureControl::Feature::kMotionLatching);
}
esp_err_t add(cluster_t *cluster)
{
VerifyOrReturnError(cluster, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Cluster cannot be NULL"));
update_feature_map(cluster, get_id());
/* Attributes managed internally */
attribute::create_latch_control_modes(cluster, 0);
return ESP_OK;
}
} /* motion_latching */
namespace instantaneous {
uint32_t get_id()
{
return static_cast<uint32_t>(ClosureControl::Feature::kInstantaneous);
}
esp_err_t add(cluster_t *cluster)
{
VerifyOrReturnError(cluster, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Cluster cannot be NULL"));
update_feature_map(cluster, get_id());
return ESP_OK;
}
} /* instantaneous */
namespace speed {
uint32_t get_id()
{
return static_cast<uint32_t>(ClosureControl::Feature::kSpeed);
}
esp_err_t add(cluster_t *cluster)
{
VerifyOrReturnError(cluster, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Cluster cannot be NULL"));
update_feature_map(cluster, get_id());
return ESP_OK;
}
} /* speed */
namespace ventilation {
uint32_t get_id()
{
return static_cast<uint32_t>(ClosureControl::Feature::kVentilation);
}
esp_err_t add(cluster_t *cluster)
{
VerifyOrReturnError(cluster, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Cluster cannot be NULL"));
update_feature_map(cluster, get_id());
return ESP_OK;
}
} /* ventilation */
namespace pedestrian {
uint32_t get_id()
{
return static_cast<uint32_t>(ClosureControl::Feature::kPedestrian);
}
esp_err_t add(cluster_t *cluster)
{
VerifyOrReturnError(cluster, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Cluster cannot be NULL"));
update_feature_map(cluster, get_id());
return ESP_OK;
}
} /* pedestrian */
namespace calibration {
uint32_t get_id()
{
return static_cast<uint32_t>(ClosureControl::Feature::kCalibration);
}
esp_err_t add(cluster_t *cluster)
{
VerifyOrReturnError(cluster, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Cluster cannot be NULL"));
update_feature_map(cluster, get_id());
command::create_calibrate(cluster);
return ESP_OK;
}
} /* calibration */
namespace protection {
uint32_t get_id()
{
return static_cast<uint32_t>(ClosureControl::Feature::kProtection);
}
esp_err_t add(cluster_t *cluster)
{
VerifyOrReturnError(cluster, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Cluster cannot be NULL"));
update_feature_map(cluster, get_id());
return ESP_OK;
}
} /* protection */
namespace manually_operable {
uint32_t get_id()
{
return static_cast<uint32_t>(ClosureControl::Feature::kManuallyOperable);
}
esp_err_t add(cluster_t *cluster)
{
VerifyOrReturnError(cluster, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Cluster cannot be NULL"));
update_feature_map(cluster, get_id());
// Events
event::create_engage_state_changed(cluster);
return ESP_OK;
}
} /* manually_operable */
} /* feature */
} /* closure_control */
} /* cluster */
} /* esp_matter */
@@ -1892,5 +1892,65 @@ namespace webrtc_transport_requestor {
}/*webrtc_transport_requestor*/
namespace closure_control {
namespace feature {
namespace positioning {
uint32_t get_id();
esp_err_t add(cluster_t *cluster);
} /* positioning */
namespace motion_latching {
uint32_t get_id();
esp_err_t add(cluster_t *cluster);
} /* motion_latching */
namespace instantaneous {
uint32_t get_id();
esp_err_t add(cluster_t *cluster);
} /* instantaneous */
namespace speed {
uint32_t get_id();
esp_err_t add(cluster_t *cluster);
} /* speed */
namespace ventilation {
uint32_t get_id();
esp_err_t add(cluster_t *cluster);
} /* ventilation */
namespace pedestrian {
uint32_t get_id();
esp_err_t add(cluster_t *cluster);
} /* pedestrian */
namespace calibration {
uint32_t get_id();
esp_err_t add(cluster_t *cluster);
} /* calibration */
namespace protection {
uint32_t get_id();
esp_err_t add(cluster_t *cluster);
} /* protection */
namespace manually_operable {
uint32_t get_id();
esp_err_t add(cluster_t *cluster);
} /* manually_operable */
} /* feature */
} /* closure_control */
} /* cluster */
} /* esp_matter */
@@ -383,6 +383,10 @@ namespace chime {
constexpr uint16_t cluster_revision = 1;
} // namespace chime
namespace closure_control {
constexpr uint16_t cluster_revision = 1;
} // namespace closure_control
} // namespace cluster
} // namespace esp_matter