From 7062551e5c430ed7b1f787fdb0f6840c8204e325 Mon Sep 17 00:00:00 2001 From: mahesh Date: Tue, 23 Dec 2025 11:45:46 +0530 Subject: [PATCH 1/3] components/esp_matter: add electrical_grid_conditions cluster in esp_matter --- .../data_model/esp_matter_attribute.cpp | 24 +++++++++++++ .../data_model/esp_matter_attribute.h | 9 +++++ .../data_model/esp_matter_cluster.cpp | 35 +++++++++++++++++++ .../data_model/esp_matter_cluster.h | 9 +++++ .../esp_matter_delegate_callbacks.cpp | 11 ++++++ .../esp_matter_delegate_callbacks.h | 1 + .../data_model/esp_matter_event.cpp | 10 ++++++ .../esp_matter/data_model/esp_matter_event.h | 6 ++++ .../data_model/esp_matter_feature.cpp | 23 ++++++++++++ .../data_model/esp_matter_feature.h | 12 +++++++ .../private/esp_matter_cluster_revisions.h | 4 +++ 11 files changed, 144 insertions(+) diff --git a/components/esp_matter/data_model/esp_matter_attribute.cpp b/components/esp_matter/data_model/esp_matter_attribute.cpp index 504ff123a..436c6aad5 100644 --- a/components/esp_matter/data_model/esp_matter_attribute.cpp +++ b/components/esp_matter/data_model/esp_matter_attribute.cpp @@ -5266,5 +5266,29 @@ attribute_t *create_maximum_metered_quantities(cluster_t *cluster, nullable value) +{ + return esp_matter::attribute::create(cluster, ElectricalGridConditions::Attributes::LocalGenerationAvailable::Id, + ATTRIBUTE_FLAG_WRITABLE | ATTRIBUTE_FLAG_MANAGED_INTERNALLY | ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_bool(value)); +} + +attribute_t *create_current_conditions(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count) +{ + return esp_matter::attribute::create(cluster, ElectricalGridConditions::Attributes::CurrentConditions::Id, + ATTRIBUTE_FLAG_MANAGED_INTERNALLY | ATTRIBUTE_FLAG_NULLABLE, esp_matter_array(value, length, count)); +} + +attribute_t *create_forecast_conditions(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count) +{ + return esp_matter::attribute::create(cluster, ElectricalGridConditions::Attributes::ForecastConditions::Id, + ATTRIBUTE_FLAG_MANAGED_INTERNALLY, esp_matter_array(value, length, count)); +} + +} /* attribute */ + +} /* electrical_grid_conditions */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/data_model/esp_matter_attribute.h b/components/esp_matter/data_model/esp_matter_attribute.h index 25536fa56..bcc5ee18c 100644 --- a/components/esp_matter/data_model/esp_matter_attribute.h +++ b/components/esp_matter/data_model/esp_matter_attribute.h @@ -1367,5 +1367,14 @@ attribute_t *create_maximum_metered_quantities(cluster_t *cluster, nullable value); +attribute_t *create_current_conditions(cluster_t *cluster, uint8_t * value, uint16_t length, uint16_t count); +attribute_t *create_forecast_conditions(cluster_t *cluster, uint8_t * value, uint16_t length, uint16_t count); +} /* attribute */ +} /* electrical_grid_conditions */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/data_model/esp_matter_cluster.cpp b/components/esp_matter/data_model/esp_matter_cluster.cpp index c019bcbe3..02775f013 100644 --- a/components/esp_matter/data_model/esp_matter_cluster.cpp +++ b/components/esp_matter/data_model/esp_matter_cluster.cpp @@ -4487,5 +4487,40 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) } /* commodity_metering */ +namespace electrical_grid_conditions { +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, ElectricalGridConditions::Id, flags); + VerifyOrReturnValue(cluster, NULL, ESP_LOGE(TAG, "Could not create cluster. cluster_id: 0x%08" PRIX32, ElectricalGridConditions::Id)); + if (flags & CLUSTER_FLAG_SERVER) { + if (config && config->delegate != nullptr) { + static const auto delegate_init_cb = ElectricalGridConditionsDelegateInitCB; + set_delegate_and_init_callback(cluster, delegate_init_cb, config->delegate); + } + static const auto plugin_server_init_cb = CALL_ONCE(MatterElectricalGridConditionsPluginServerInitCallback); + set_plugin_server_init_callback(cluster, plugin_server_init_cb); + add_function_list(cluster, function_list, function_flags); + + /* Attributes managed internally */ + global::attribute::create_feature_map(cluster, 0); + attribute::create_local_generation_available(cluster, false); + attribute::create_current_conditions(cluster, NULL, 0, 0); + + /* Attributes not managed internally */ + global::attribute::create_cluster_revision(cluster, cluster_revision); + } + + if (flags & CLUSTER_FLAG_CLIENT) { + create_default_binding_cluster(endpoint); + } + return cluster; +} + +} /* electrical_grid_conditions */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/data_model/esp_matter_cluster.h b/components/esp_matter/data_model/esp_matter_cluster.h index ed23517e4..fc00d3abf 100644 --- a/components/esp_matter/data_model/esp_matter_cluster.h +++ b/components/esp_matter/data_model/esp_matter_cluster.h @@ -1062,5 +1062,14 @@ using config_t = common::config_t; cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); } /* commodity_metering */ +namespace electrical_grid_conditions { +typedef struct config { + void *delegate; + config() : delegate(nullptr) {} +} config_t; + +cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); +} /* electrical_grid_conditions */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/data_model/esp_matter_delegate_callbacks.cpp b/components/esp_matter/data_model/esp_matter_delegate_callbacks.cpp index c7da48e93..c20248397 100644 --- a/components/esp_matter/data_model/esp_matter_delegate_callbacks.cpp +++ b/components/esp_matter/data_model/esp_matter_delegate_callbacks.cpp @@ -53,6 +53,7 @@ #include #include #include +#include #include using namespace chip::app::Clusters; @@ -606,6 +607,16 @@ void CommodityPriceDelegateInitCB(void *delegate, uint16_t endpoint_id) commodity_price_instance->Init(); } + +void ElectricalGridConditionsDelegateInitCB(void *delegate, uint16_t endpoint_id) +{ + VerifyOrReturn(delegate != nullptr); + ElectricalGridConditions::Delegate *electrical_grid_conditions_delegate = static_cast(delegate); + uint32_t feature_map = get_feature_map_value(endpoint_id, ElectricalGridConditions::Id); + ElectricalGridConditions::Instance *electrical_grid_conditions_instance = new ElectricalGridConditions::Instance(endpoint_id, *electrical_grid_conditions_delegate, chip::BitMask(feature_map)); + electrical_grid_conditions_instance->Init(); +} + } // namespace delegate_cb } // namespace cluster } // namespace esp_matter diff --git a/components/esp_matter/data_model/esp_matter_delegate_callbacks.h b/components/esp_matter/data_model/esp_matter_delegate_callbacks.h index dba9f5812..61ade43bc 100644 --- a/components/esp_matter/data_model/esp_matter_delegate_callbacks.h +++ b/components/esp_matter/data_model/esp_matter_delegate_callbacks.h @@ -61,6 +61,7 @@ void ClosureDimensionDelegateInitCB(void *delegate, uint16_t endpoint_id); void PushAvStreamTransportDelegateInitCB(void *delegate, uint16_t endpoint_id); void CommodityTariffDelegateInitCB(void *delegate, uint16_t endpoint_id); void CommodityPriceDelegateInitCB(void *delegate, uint16_t endpoint_id); +void ElectricalGridConditionsDelegateInitCB(void *delegate, uint16_t endpoint_id); } // namespace delegate_cb } // namespace cluster diff --git a/components/esp_matter/data_model/esp_matter_event.cpp b/components/esp_matter/data_model/esp_matter_event.cpp index d4fbddbc6..1d5cf16d3 100644 --- a/components/esp_matter/data_model/esp_matter_event.cpp +++ b/components/esp_matter/data_model/esp_matter_event.cpp @@ -892,5 +892,15 @@ event_t *create_price_change(cluster_t *cluster) } // namespace event } // namespace commodity_price +namespace electrical_grid_conditions { +namespace event { +event_t *create_current_conditions_changed(cluster_t *cluster) +{ + return esp_matter::event::create(cluster, ElectricalGridConditions::Events::CurrentConditionsChanged::Id); +} + +} // namespace event +} // namespace electrical_grid_conditions + } // namespace cluster } // namespace esp_matter diff --git a/components/esp_matter/data_model/esp_matter_event.h b/components/esp_matter/data_model/esp_matter_event.h index cdf8f513a..a2e1bf94a 100644 --- a/components/esp_matter/data_model/esp_matter_event.h +++ b/components/esp_matter/data_model/esp_matter_event.h @@ -285,5 +285,11 @@ event_t *create_price_change(cluster_t *cluster); } // namespace event } // namespace commodity_price +namespace electrical_grid_conditions { +namespace event { +event_t *create_current_conditions_changed(cluster_t *cluster); +} // namespace event +} // namespace electrical_grid_conditions + } // namespace cluster } // namespace esp_matter diff --git a/components/esp_matter/data_model/esp_matter_feature.cpp b/components/esp_matter/data_model/esp_matter_feature.cpp index 77c32dcc4..701fd9f3a 100644 --- a/components/esp_matter/data_model/esp_matter_feature.cpp +++ b/components/esp_matter/data_model/esp_matter_feature.cpp @@ -4664,5 +4664,28 @@ esp_err_t add(cluster_t *cluster) } /* feature */ } /* commodity_price */ +namespace electrical_grid_conditions { +namespace feature { +namespace forecasting { + +uint32_t get_id() +{ + return static_cast(ElectricalGridConditions::Feature::kForecasting); +} + +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 + attribute::create_forecast_conditions(cluster, NULL, 0, 0); + return ESP_OK; +} + +} /* forecasting */ + +} /* feature */ +} /* electrical_grid_conditions */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/data_model/esp_matter_feature.h b/components/esp_matter/data_model/esp_matter_feature.h index f1d693ea1..4725cd7df 100644 --- a/components/esp_matter/data_model/esp_matter_feature.h +++ b/components/esp_matter/data_model/esp_matter_feature.h @@ -2085,5 +2085,17 @@ esp_err_t add(cluster_t *cluster); } /* feature */ } /* commodity_price */ +namespace electrical_grid_conditions { +namespace feature { + +namespace forecasting { + +uint32_t get_id(); +esp_err_t add(cluster_t *cluster); +} /* forecasting */ + +} /* feature */ +} /* electrical_grid_conditions */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/data_model/private/esp_matter_cluster_revisions.h b/components/esp_matter/data_model/private/esp_matter_cluster_revisions.h index de6804a35..ae376d582 100644 --- a/components/esp_matter/data_model/private/esp_matter_cluster_revisions.h +++ b/components/esp_matter/data_model/private/esp_matter_cluster_revisions.h @@ -410,6 +410,10 @@ constexpr uint16_t cluster_revision = 4; namespace commodity_metering { constexpr uint16_t cluster_revision = 1; } // namespace commodity_metering + +namespace electrical_grid_conditions { +constexpr uint16_t cluster_revision = 1; +} // namespace electrical_grid_conditions } // namespace cluster } // namespace esp_matter From be23174ecb687ebe3b8930dac8f4495d8d005fe2 Mon Sep 17 00:00:00 2001 From: mahesh Date: Fri, 28 Nov 2025 17:55:19 +0530 Subject: [PATCH 2/3] components/esp_matter: add meter_identification cluster in esp_matter --- .../data_model/esp_matter_attribute.cpp | 36 +++++++++++++++++++ .../data_model/esp_matter_attribute.h | 11 ++++++ .../data_model/esp_matter_cluster.cpp | 32 +++++++++++++++++ .../data_model/esp_matter_cluster.h | 6 ++++ .../data_model/esp_matter_feature.cpp | 23 ++++++++++++ .../data_model/esp_matter_feature.h | 12 +++++++ .../private/esp_matter_cluster_revisions.h | 4 +++ 7 files changed, 124 insertions(+) diff --git a/components/esp_matter/data_model/esp_matter_attribute.cpp b/components/esp_matter/data_model/esp_matter_attribute.cpp index 436c6aad5..fa3c3b7f5 100644 --- a/components/esp_matter/data_model/esp_matter_attribute.cpp +++ b/components/esp_matter/data_model/esp_matter_attribute.cpp @@ -5290,5 +5290,41 @@ attribute_t *create_forecast_conditions(cluster_t *cluster, uint8_t *value, uint } /* electrical_grid_conditions */ +namespace meter_identification { +namespace attribute { +attribute_t *create_meter_type(cluster_t *cluster, nullable value) +{ + return esp_matter::attribute::create(cluster, MeterIdentification::Attributes::MeterType::Id, + ATTRIBUTE_FLAG_MANAGED_INTERNALLY | ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_enum8(value)); +} + +attribute_t *create_point_of_delivery(cluster_t *cluster, char *value, uint16_t length) +{ + return esp_matter::attribute::create(cluster, MeterIdentification::Attributes::PointOfDelivery::Id, + ATTRIBUTE_FLAG_MANAGED_INTERNALLY | ATTRIBUTE_FLAG_NULLABLE, esp_matter_char_str(value, length)); +} + +attribute_t *create_meter_serial_number(cluster_t *cluster, char *value, uint16_t length) +{ + return esp_matter::attribute::create(cluster, MeterIdentification::Attributes::MeterSerialNumber::Id, + ATTRIBUTE_FLAG_MANAGED_INTERNALLY | ATTRIBUTE_FLAG_NULLABLE, esp_matter_char_str(value, length)); +} + +attribute_t *create_protocol_version(cluster_t *cluster, char *value, uint16_t length) +{ + return esp_matter::attribute::create(cluster, MeterIdentification::Attributes::ProtocolVersion::Id, + ATTRIBUTE_FLAG_MANAGED_INTERNALLY | ATTRIBUTE_FLAG_NULLABLE, esp_matter_char_str(value, length)); +} + +attribute_t *create_power_threshold(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count) +{ + return esp_matter::attribute::create(cluster, MeterIdentification::Attributes::PowerThreshold::Id, + ATTRIBUTE_FLAG_MANAGED_INTERNALLY | ATTRIBUTE_FLAG_NULLABLE, esp_matter_array(value, length, count)); +} + +} /* attribute */ + +} /* meter_identification */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/data_model/esp_matter_attribute.h b/components/esp_matter/data_model/esp_matter_attribute.h index bcc5ee18c..33abfc026 100644 --- a/components/esp_matter/data_model/esp_matter_attribute.h +++ b/components/esp_matter/data_model/esp_matter_attribute.h @@ -1376,5 +1376,16 @@ attribute_t *create_forecast_conditions(cluster_t *cluster, uint8_t * value, uin } /* attribute */ } /* electrical_grid_conditions */ +namespace meter_identification { +namespace attribute { + +attribute_t *create_meter_type(cluster_t *cluster, nullable value); +attribute_t *create_point_of_delivery(cluster_t *cluster, char * value, uint16_t length); +attribute_t *create_meter_serial_number(cluster_t *cluster, char * value, uint16_t length); +attribute_t *create_protocol_version(cluster_t *cluster, char * value, uint16_t length); +attribute_t *create_power_threshold(cluster_t *cluster, uint8_t * value, uint16_t length, uint16_t count); +} /* attribute */ +} /* meter_identification */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/data_model/esp_matter_cluster.cpp b/components/esp_matter/data_model/esp_matter_cluster.cpp index 02775f013..f64a4e4f6 100644 --- a/components/esp_matter/data_model/esp_matter_cluster.cpp +++ b/components/esp_matter/data_model/esp_matter_cluster.cpp @@ -4522,5 +4522,37 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) } /* electrical_grid_conditions */ +namespace meter_identification { +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, MeterIdentification::Id, flags); + VerifyOrReturnValue(cluster, NULL, ESP_LOGE(TAG, "Could not create cluster. cluster_id: 0x%08" PRIX32, MeterIdentification::Id)); + if (flags & CLUSTER_FLAG_SERVER) { + static const auto plugin_server_init_cb = CALL_ONCE(MatterMeterIdentificationPluginServerInitCallback); + set_plugin_server_init_callback(cluster, plugin_server_init_cb); + add_function_list(cluster, function_list, function_flags); + + /* Attributes managed internally */ + global::attribute::create_feature_map(cluster, 0); + attribute::create_meter_type(cluster, 0); + attribute::create_point_of_delivery(cluster, NULL, 0); + attribute::create_meter_serial_number(cluster, NULL, 0); + + /* Attributes not managed internally */ + global::attribute::create_cluster_revision(cluster, cluster_revision); + } + + if (flags & CLUSTER_FLAG_CLIENT) { + create_default_binding_cluster(endpoint); + } + return cluster; +} + +} /* meter_identification */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/data_model/esp_matter_cluster.h b/components/esp_matter/data_model/esp_matter_cluster.h index fc00d3abf..4ea41b346 100644 --- a/components/esp_matter/data_model/esp_matter_cluster.h +++ b/components/esp_matter/data_model/esp_matter_cluster.h @@ -1071,5 +1071,11 @@ typedef struct config { cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); } /* electrical_grid_conditions */ +namespace meter_identification { +using config_t = common::config_t; + +cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); +} /* meter_identification */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/data_model/esp_matter_feature.cpp b/components/esp_matter/data_model/esp_matter_feature.cpp index 701fd9f3a..b2dbd804d 100644 --- a/components/esp_matter/data_model/esp_matter_feature.cpp +++ b/components/esp_matter/data_model/esp_matter_feature.cpp @@ -4687,5 +4687,28 @@ esp_err_t add(cluster_t *cluster) } /* feature */ } /* electrical_grid_conditions */ +namespace meter_identification { +namespace feature { +namespace power_threshold { + +uint32_t get_id() +{ + return static_cast(MeterIdentification::Feature::kPowerThreshold); +} + +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 + attribute::create_power_threshold(cluster, NULL, 0, 0); + return ESP_OK; +} + +} /* power_threshold */ + +} /* feature */ +} /* meter_identification */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/data_model/esp_matter_feature.h b/components/esp_matter/data_model/esp_matter_feature.h index 4725cd7df..8f5a2d08a 100644 --- a/components/esp_matter/data_model/esp_matter_feature.h +++ b/components/esp_matter/data_model/esp_matter_feature.h @@ -2097,5 +2097,17 @@ esp_err_t add(cluster_t *cluster); } /* feature */ } /* electrical_grid_conditions */ +namespace meter_identification { +namespace feature { + +namespace power_threshold { + +uint32_t get_id(); +esp_err_t add(cluster_t *cluster); +} /* power_threshold */ + +} /* feature */ +} /* meter_identification */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/data_model/private/esp_matter_cluster_revisions.h b/components/esp_matter/data_model/private/esp_matter_cluster_revisions.h index ae376d582..75185915d 100644 --- a/components/esp_matter/data_model/private/esp_matter_cluster_revisions.h +++ b/components/esp_matter/data_model/private/esp_matter_cluster_revisions.h @@ -414,6 +414,10 @@ constexpr uint16_t cluster_revision = 1; namespace electrical_grid_conditions { constexpr uint16_t cluster_revision = 1; } // namespace electrical_grid_conditions + +namespace meter_identification { +constexpr uint16_t cluster_revision = 1; +} // namespace meter_identification } // namespace cluster } // namespace esp_matter From 7103c33545b3dd92ec8857c503ceef6c3bd5b6ae Mon Sep 17 00:00:00 2001 From: mahesh Date: Tue, 23 Dec 2025 15:22:01 +0530 Subject: [PATCH 3/3] components/esp_matter: Add new electrical device types --- components/esp_matter/CMakeLists.txt | 3 - .../esp_matter_attribute_bounds.cpp | 74 ------------------ .../data_model/esp_matter_attribute_bounds.h | 11 --- .../data_model/esp_matter_cluster.cpp | 3 - .../data_model/esp_matter_endpoint.cpp | 75 +++++++++++++++++++ .../data_model/esp_matter_endpoint.h | 43 ++++++++++- ...sp_matter_plugin_server_init_callbacks.cpp | 2 + .../all_device_types_app/main/device_types.h | 6 ++ .../main/esp_matter_console_helpers.cpp | 28 +++++++ 9 files changed, 153 insertions(+), 92 deletions(-) diff --git a/components/esp_matter/CMakeLists.txt b/components/esp_matter/CMakeLists.txt index ecb13287b..1e13bda50 100644 --- a/components/esp_matter/CMakeLists.txt +++ b/components/esp_matter/CMakeLists.txt @@ -10,9 +10,6 @@ set(INCLUDE_DIRS_LIST "." "${MATTER_SDK_PATH}/third_party/nlfaultinjection/include" "${MATTER_SDK_PATH}/src") -# TODO: These files have compilation errors -set(EXCLUDE_SRCS_LIST "${MATTER_SDK_PATH}/src/app/clusters/commodity-tariff-server/commodity-tariff-server.cpp" - "${MATTER_SDK_PATH}/src/app/clusters/commodity-tariff-server/CommodityTariffAttrsDataMgmt.cpp") set(PRIV_INCLUDE_DIRS_LIST ) if (CONFIG_ESP_MATTER_ENABLE_MATTER_SERVER) diff --git a/components/esp_matter/data_model/esp_matter_attribute_bounds.cpp b/components/esp_matter/data_model/esp_matter_attribute_bounds.cpp index ab0589076..c4458ae4a 100644 --- a/components/esp_matter/data_model/esp_matter_attribute_bounds.cpp +++ b/components/esp_matter/data_model/esp_matter_attribute_bounds.cpp @@ -676,79 +676,5 @@ void add_bounds_cb(cluster_t *cluster) } } /* camera_av_settings_user_level_management */ -namespace commodity_tariff { - -void add_bounds_cb(cluster_t *cluster) -{ - VerifyOrReturn(cluster != nullptr, ESP_LOGE(TAG, "Cluster is NULL. Add bounds Failed!!")); - attribute_t *current_attribute = esp_matter::attribute::get_first(cluster); - VerifyOrReturn(current_attribute != nullptr, ESP_LOGE(TAG, "Attribute is NULL.")); - while(current_attribute) { - switch(esp_matter::attribute::get_id(current_attribute)) { - case CommodityTariff::Attributes::TariffUnit::Id: { - uint8_t min = 0, max = 1; - esp_matter::attribute::add_bounds(current_attribute, esp_matter_enum8(min), esp_matter_enum8(max)); - break; - } - case CommodityTariff::Attributes::DefaultRandomizationType::Id: { - uint8_t min = 0, max = 4; - esp_matter::attribute::add_bounds(current_attribute, esp_matter_enum8(min), esp_matter_enum8(max)); - break; - } - default: - break; - } - current_attribute = esp_matter::attribute::get_next(current_attribute); - } -} -} /* commodity_tariff */ - -namespace commodity_price { -void add_bounds_cb(cluster_t *cluster) -{ - VerifyOrReturn(cluster != nullptr, ESP_LOGE(TAG, "Cluster is NULL. Add bounds Failed!!")); - attribute_t *current_attribute = esp_matter::attribute::get_first(cluster); - VerifyOrReturn(current_attribute != nullptr, ESP_LOGE(TAG, "Attribute is NULL.")); - while(current_attribute) { - switch(esp_matter::attribute::get_id(current_attribute)) { - case CommodityPrice::Attributes::TariffUnit::Id: { - uint8_t min = 0, max = 1; - esp_matter::attribute::add_bounds(current_attribute, esp_matter_enum8(min), esp_matter_enum8(max)); - break; - } - default: - break; - } - current_attribute = esp_matter::attribute::get_next(current_attribute); - } -} -} /* commodity_price */ - -namespace commodity_metering { - -void add_bounds_cb(cluster_t *cluster) -{ - VerifyOrReturn(cluster != nullptr, ESP_LOGE(TAG, "Cluster is NULL. Add bounds Failed!!")); - attribute_t *current_attribute = esp_matter::attribute::get_first(cluster); - VerifyOrReturn(current_attribute != nullptr, ESP_LOGE(TAG, "Attribute is NULL.")); - while(current_attribute) { - switch(esp_matter::attribute::get_id(current_attribute)) { - case CommodityMetering::Attributes::MaximumMeteredQuantities::Id: { - uint16_t min = 1, max = UINT16_MAX; - esp_matter::attribute::add_bounds(current_attribute, esp_matter_uint16(min), esp_matter_uint16(max)); - break; - } - case CommodityMetering::Attributes::TariffUnit::Id: { - uint8_t min = 0, max = 1; - esp_matter::attribute::add_bounds(current_attribute, esp_matter_enum8(min), esp_matter_enum8(max)); - break; - } - default: - break; - } - current_attribute = esp_matter::attribute::get_next(current_attribute); - } -} -} /* commodity_metering */ } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/data_model/esp_matter_attribute_bounds.h b/components/esp_matter/data_model/esp_matter_attribute_bounds.h index 0b845e0cc..efd024352 100644 --- a/components/esp_matter/data_model/esp_matter_attribute_bounds.h +++ b/components/esp_matter/data_model/esp_matter_attribute_bounds.h @@ -50,16 +50,5 @@ namespace camera_av_settings_user_level_management { void add_bounds_cb(cluster_t *cluster); } /* camera_av_settings_user_level_management */ -namespace commodity_tariff { -void add_bounds_cb(cluster_t *cluster); -} /* commodity_tariff */ - -namespace commodity_price { -void add_bounds_cb(cluster_t *cluster); -} /* commodity_price */ - -namespace commodity_metering { -void add_bounds_cb(cluster_t *cluster); -} /* commodity_metering */ } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/data_model/esp_matter_cluster.cpp b/components/esp_matter/data_model/esp_matter_cluster.cpp index f64a4e4f6..184aaf7e3 100644 --- a/components/esp_matter/data_model/esp_matter_cluster.cpp +++ b/components/esp_matter/data_model/esp_matter_cluster.cpp @@ -4352,7 +4352,6 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) } static const auto plugin_server_init_cb = CALL_ONCE(MatterCommodityTariffPluginServerInitCallback); set_plugin_server_init_callback(cluster, plugin_server_init_cb); - set_add_bounds_callback(cluster, commodity_tariff::add_bounds_cb); add_function_list(cluster, function_list, function_flags); VerifyOrReturnValue(config != NULL, ABORT_CLUSTER_CREATE(cluster)); @@ -4432,7 +4431,6 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) } static const auto plugin_server_init_cb = CALL_ONCE(MatterCommodityPricePluginServerInitCallback); set_plugin_server_init_callback(cluster, plugin_server_init_cb); - set_add_bounds_callback(cluster, commodity_price::add_bounds_cb); add_function_list(cluster, function_list, function_flags); /* Attributes managed internally */ @@ -4465,7 +4463,6 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) if (flags & CLUSTER_FLAG_SERVER) { static const auto plugin_server_init_cb = CALL_ONCE(MatterCommodityMeteringPluginServerInitCallback); set_plugin_server_init_callback(cluster, plugin_server_init_cb); - set_add_bounds_callback(cluster, commodity_metering::add_bounds_cb); add_function_list(cluster, function_list, function_flags); /* Attributes managed internally */ diff --git a/components/esp_matter/data_model/esp_matter_endpoint.cpp b/components/esp_matter/data_model/esp_matter_endpoint.cpp index fae9a5eff..eddb89216 100644 --- a/components/esp_matter/data_model/esp_matter_endpoint.cpp +++ b/components/esp_matter/data_model/esp_matter_endpoint.cpp @@ -2199,6 +2199,81 @@ esp_err_t add(endpoint_t *endpoint, config_t *config) return ESP_OK; } } /* closure_panel */ + +namespace electrical_utility_meter { +uint32_t get_device_type_id() +{ + return ESP_MATTER_ELECTRICAL_UTILITY_METER_DEVICE_TYPE_ID; +} + +uint8_t get_device_type_version() +{ + return ESP_MATTER_ELECTRICAL_UTILITY_METER_DEVICE_TYPE_VERSION; +} + +endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) +{ + return common::create(node, config, flags, priv_data, add); +} + +esp_err_t add(endpoint_t *endpoint, config_t *config) +{ + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + VerifyOrReturnError(err == ESP_OK, err); + cluster::meter_identification::create(endpoint, &(config->meter_identification), CLUSTER_FLAG_SERVER); + return ESP_OK; +} +} /* electrical_utility_meter */ + +namespace electrical_energy_tariff { +uint32_t get_device_type_id() +{ + return ESP_MATTER_ELECTRICAL_ENERGY_TARIFF_DEVICE_TYPE_ID; +} + +uint8_t get_device_type_version() +{ + return ESP_MATTER_ELECTRICAL_ENERGY_TARIFF_DEVICE_TYPE_VERSION; +} + +endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) +{ + return common::create(node, config, flags, priv_data, add); +} + +esp_err_t add(endpoint_t *endpoint, config_t *config) +{ + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + VerifyOrReturnError(err == ESP_OK, err); + return ESP_OK; +} +} /* electrical_energy_tariff */ + +namespace electrical_meter { +uint32_t get_device_type_id() +{ + return ESP_MATTER_ELECTRICAL_METER_DEVICE_TYPE_ID; +} + +uint8_t get_device_type_version() +{ + return ESP_MATTER_ELECTRICAL_METER_DEVICE_TYPE_VERSION; +} + +endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) +{ + return common::create(node, config, flags, priv_data, add); +} + +esp_err_t add(endpoint_t *endpoint, config_t *config) +{ + esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + VerifyOrReturnError(err == ESP_OK, err); + cluster::electrical_power_measurement::create(endpoint, &(config->electrical_power_measurement), CLUSTER_FLAG_SERVER); + cluster::electrical_energy_measurement::create(endpoint, &(config->electrical_energy_measurement), CLUSTER_FLAG_SERVER); + return ESP_OK; +} +} /* electrical_meter */ } /* endpoint */ namespace node { diff --git a/components/esp_matter/data_model/esp_matter_endpoint.h b/components/esp_matter/data_model/esp_matter_endpoint.h index d781b107f..6af8e1a06 100644 --- a/components/esp_matter/data_model/esp_matter_endpoint.h +++ b/components/esp_matter/data_model/esp_matter_endpoint.h @@ -161,7 +161,12 @@ #define ESP_MATTER_CLOSURE_PANEL_DEVICE_TYPE_VERSION 1 #define ESP_MATTER_CHIME_DEVICE_TYPE_ID 0x0146 #define ESP_MATTER_CHIME_DEVICE_TYPE_VERSION 1 - +#define ESP_MATTER_ELECTRICAL_UTILITY_METER_DEVICE_TYPE_ID 0x0511 +#define ESP_MATTER_ELECTRICAL_UTILITY_METER_DEVICE_TYPE_VERSION 1 +#define ESP_MATTER_ELECTRICAL_ENERGY_TARIFF_DEVICE_TYPE_ID 0x0513 +#define ESP_MATTER_ELECTRICAL_ENERGY_TARIFF_DEVICE_TYPE_VERSION 1 +#define ESP_MATTER_ELECTRICAL_METER_DEVICE_TYPE_ID 0x0514 +#define ESP_MATTER_ELECTRICAL_METER_DEVICE_TYPE_VERSION 1 namespace esp_matter { /** Specific endpoint (device type) create APIs @@ -1108,6 +1113,42 @@ 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); } /* closure_panel */ + +namespace electrical_utility_meter { +typedef struct config { + cluster::descriptor::config_t descriptor; + cluster::meter_identification::config_t meter_identification; +} 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); +} /* electrical_utility_meter */ + +namespace electrical_energy_tariff { +typedef struct config { + cluster::descriptor::config_t descriptor; +} 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); +} /* electrical_energy_tariff */ + +namespace electrical_meter { +typedef struct config { + cluster::descriptor::config_t descriptor; + cluster::electrical_power_measurement::config_t electrical_power_measurement; + cluster::electrical_energy_measurement::config_t electrical_energy_measurement; +} 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); +} /* electrical_meter */ } /* endpoint */ namespace node { diff --git a/components/esp_matter/data_model_provider/esp_matter_plugin_server_init_callbacks.cpp b/components/esp_matter/data_model_provider/esp_matter_plugin_server_init_callbacks.cpp index b600985d1..81272dcc7 100644 --- a/components/esp_matter/data_model_provider/esp_matter_plugin_server_init_callbacks.cpp +++ b/components/esp_matter/data_model_provider/esp_matter_plugin_server_init_callbacks.cpp @@ -67,6 +67,8 @@ void MatterElectricalPowerMeasurementPluginServerInitCallback() {} void MatterServiceAreaPluginServerInitCallback() {} void MatterWaterHeaterManagementPluginServerInitCallback() {} void MatterWaterHeaterModePluginServerInitCallback() {} +void MatterCommodityTariffPluginServerInitCallback() {} void MatterCommodityPricePluginServerInitCallback() {} +void MatterCommodityMeteringPluginServerInitCallback() {} void MatterElectricalGridConditionsPluginServerInitCallback() {} void MatterSoilMeasurementPluginServerInitCallback() {} diff --git a/examples/all_device_types_app/main/device_types.h b/examples/all_device_types_app/main/device_types.h index 461fb93db..b955d8722 100644 --- a/examples/all_device_types_app/main/device_types.h +++ b/examples/all_device_types_app/main/device_types.h @@ -64,6 +64,9 @@ enum device_type_enum { ESP_MATTER_CLOSURE_CONTROLLER, ESP_MATTER_CLOSURE, ESP_MATTER_CLOSURE_PANEL, + ESP_MATTER_ELECTRICAL_ENERGY_TARIFF, + ESP_MATTER_ELECTRICAL_METER, + ESP_MATTER_ELECTRICAL_UTILITY_METER, ESP_MATTER_DEVICE_TYPE_MAX }; @@ -134,5 +137,8 @@ const device_type_name device_type_list[ESP_MATTER_DEVICE_TYPE_MAX] = { {"closure_controller", ESP_MATTER_CLOSURE_CONTROLLER}, {"closure", ESP_MATTER_CLOSURE}, {"closure_panel", ESP_MATTER_CLOSURE_PANEL}, + {"electrical_energy_tariff", ESP_MATTER_ELECTRICAL_ENERGY_TARIFF}, + {"electrical_meter", ESP_MATTER_ELECTRICAL_METER}, + {"electrical_utility_meter", ESP_MATTER_ELECTRICAL_UTILITY_METER}, }; } /* namespace esp_matter */ 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 7a5de910a..26fba07fe 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 @@ -613,6 +613,34 @@ int create(uint8_t device_type_index) endpoint = esp_matter::endpoint::closure_panel::create(node, &closure_panel_config, ENDPOINT_FLAG_NONE, NULL); break; } + case ESP_MATTER_ELECTRICAL_ENERGY_TARIFF: { + esp_matter::endpoint::electrical_energy_tariff::config_t electrical_energy_tariff_config; + endpoint = esp_matter::endpoint::electrical_energy_tariff::create(node, &electrical_energy_tariff_config, ENDPOINT_FLAG_NONE, NULL); + + cluster::commodity_price::config_t commodity_price_config; + cluster::commodity_price::create(endpoint, &commodity_price_config, CLUSTER_FLAG_SERVER); + + cluster::commodity_tariff::config_t commodity_tariff_config; + commodity_tariff_config.feature_flags = cluster::commodity_tariff::feature::pricing::get_id(); + cluster::commodity_tariff::create(endpoint, &commodity_tariff_config, CLUSTER_FLAG_SERVER); + + break; + } + case ESP_MATTER_ELECTRICAL_METER: { + esp_matter::endpoint::electrical_meter::config_t electrical_meter_config; + electrical_meter_config.electrical_power_measurement.feature_flags = cluster::electrical_power_measurement::feature::direct_current::get_id(); + electrical_meter_config.electrical_energy_measurement.feature_flags = cluster::electrical_energy_measurement::feature::imported_energy::get_id() | + cluster::electrical_energy_measurement::feature::exported_energy::get_id() | + cluster::electrical_energy_measurement::feature::cumulative_energy::get_id() | + cluster::electrical_energy_measurement::feature::periodic_energy::get_id(); + endpoint = esp_matter::endpoint::electrical_meter::create(node, &electrical_meter_config, ENDPOINT_FLAG_NONE, NULL); + break; + } + case ESP_MATTER_ELECTRICAL_UTILITY_METER: { + esp_matter::endpoint::electrical_utility_meter::config_t electrical_utility_meter_config; + endpoint = esp_matter::endpoint::electrical_utility_meter::create(node, &electrical_utility_meter_config, ENDPOINT_FLAG_NONE, NULL); + break; + } default: { ESP_LOGE(TAG, "Please input a valid device type"); break;