From 0293116894631eab140a616331cc472b528a1964 Mon Sep 17 00:00:00 2001 From: mahesh Date: Fri, 28 Nov 2025 17:21:27 +0530 Subject: [PATCH] components/esp_matter: add commodity_price cluster in esp_matter --- .../data_model/esp_matter_attribute.cpp | 29 +++++++++++++++ .../data_model/esp_matter_attribute.h | 9 +++++ .../esp_matter_attribute_bounds.cpp | 21 +++++++++++ .../data_model/esp_matter_attribute_bounds.h | 4 ++ .../data_model/esp_matter_cluster.cpp | 37 +++++++++++++++++++ .../data_model/esp_matter_cluster.h | 9 +++++ .../data_model/esp_matter_command.cpp | 29 +++++++++++++++ .../data_model/esp_matter_command.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 ++ 15 files changed, 214 insertions(+) diff --git a/components/esp_matter/data_model/esp_matter_attribute.cpp b/components/esp_matter/data_model/esp_matter_attribute.cpp index 240db7dce..c8fd999aa 100644 --- a/components/esp_matter/data_model/esp_matter_attribute.cpp +++ b/components/esp_matter/data_model/esp_matter_attribute.cpp @@ -5207,5 +5207,34 @@ attribute_t *create_default_randomization_type(cluster_t *cluster, nullabledelegate != nullptr) { + static const auto delegate_init_cb = CommodityPriceDelegateInitCB; + set_delegate_and_init_callback(cluster, delegate_init_cb, config->delegate); + } + 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 */ + global::attribute::create_feature_map(cluster, 0); + attribute::create_tariff_unit(cluster, 0); + attribute::create_currency(cluster, NULL, 0, 0); + attribute::create_current_price(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; +} + +} /* commodity_price */ + } /* 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 04437e6ba..b79b0a10d 100644 --- a/components/esp_matter/data_model/esp_matter_cluster.h +++ b/components/esp_matter/data_model/esp_matter_cluster.h @@ -1048,5 +1048,14 @@ typedef struct config { cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); } /* commodity_tariff */ +namespace commodity_price { +typedef struct config { + void *delegate; + config() : delegate(nullptr) {} +} config_t; + +cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); +} /* commodity_price */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/data_model/esp_matter_command.cpp b/components/esp_matter/data_model/esp_matter_command.cpp index e602ccc3e..eadc65232 100644 --- a/components/esp_matter/data_model/esp_matter_command.cpp +++ b/components/esp_matter/data_model/esp_matter_command.cpp @@ -3175,5 +3175,34 @@ command_t *create_get_day_entry_response(cluster_t *cluster) } /* command */ } /* commodity_tariff */ +namespace commodity_price { +namespace command { +command_t *create_get_detailed_price_request(cluster_t *cluster) +{ + return esp_matter::command::create(cluster, CommodityPrice::Commands::GetDetailedPriceRequest::Id, + COMMAND_FLAG_ACCEPTED, NULL); +} + +command_t *create_get_detailed_price_response(cluster_t *cluster) +{ + return esp_matter::command::create(cluster, CommodityPrice::Commands::GetDetailedPriceResponse::Id, + COMMAND_FLAG_GENERATED, NULL); +} + +command_t *create_get_detailed_forecast_request(cluster_t *cluster) +{ + return esp_matter::command::create(cluster, CommodityPrice::Commands::GetDetailedForecastRequest::Id, + COMMAND_FLAG_ACCEPTED, NULL); +} + +command_t *create_get_detailed_forecast_response(cluster_t *cluster) +{ + return esp_matter::command::create(cluster, CommodityPrice::Commands::GetDetailedForecastResponse::Id, + COMMAND_FLAG_GENERATED, NULL); +} + +} /* command */ +} /* commodity_price */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/data_model/esp_matter_command.h b/components/esp_matter/data_model/esp_matter_command.h index 342b9c196..56acfce82 100644 --- a/components/esp_matter/data_model/esp_matter_command.h +++ b/components/esp_matter/data_model/esp_matter_command.h @@ -600,5 +600,14 @@ command_t *create_get_day_entry_response(cluster_t *cluster); } /* command */ } /* commodity_tariff */ +namespace commodity_price { +namespace command { +command_t *create_get_detailed_price_request(cluster_t *cluster); +command_t *create_get_detailed_price_response(cluster_t *cluster); +command_t *create_get_detailed_forecast_request(cluster_t *cluster); +command_t *create_get_detailed_forecast_response(cluster_t *cluster); +} /* command */ +} /* commodity_price */ + } /* 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 7fb320a64..c7da48e93 100644 --- a/components/esp_matter/data_model/esp_matter_delegate_callbacks.cpp +++ b/components/esp_matter/data_model/esp_matter_delegate_callbacks.cpp @@ -52,6 +52,7 @@ #include #include #include +#include #include using namespace chip::app::Clusters; @@ -595,6 +596,16 @@ void CommodityTariffDelegateInitCB(void *delegate, uint16_t endpoint_id) commodity_tariff_instance->Init(); } + +void CommodityPriceDelegateInitCB(void *delegate, uint16_t endpoint_id) +{ + VerifyOrReturn(delegate != nullptr); + CommodityPrice::Delegate *commodity_price_delegate = static_cast(delegate); + uint32_t feature_map = get_feature_map_value(endpoint_id, CommodityPrice::Id); + CommodityPrice::Instance *commodity_price_instance = new CommodityPrice::Instance(endpoint_id, *commodity_price_delegate, chip::BitMask(feature_map)); + commodity_price_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 1fa2effc2..dba9f5812 100644 --- a/components/esp_matter/data_model/esp_matter_delegate_callbacks.h +++ b/components/esp_matter/data_model/esp_matter_delegate_callbacks.h @@ -60,6 +60,7 @@ void ClosureControlDelegateInitCB(void *delegate, uint16_t endpoint_id); 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); } // 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 14d11077e..d4fbddbc6 100644 --- a/components/esp_matter/data_model/esp_matter_event.cpp +++ b/components/esp_matter/data_model/esp_matter_event.cpp @@ -882,5 +882,15 @@ event_t *create_push_transport_end(cluster_t *cluster) } // namespace event } // namespace push_av_stream_transport +namespace commodity_price { +namespace event { +event_t *create_price_change(cluster_t *cluster) +{ + return esp_matter::event::create(cluster, CommodityPrice::Events::PriceChange::Id); +} + +} // namespace event +} // namespace commodity_price + } // 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 26da3f6ff..cdf8f513a 100644 --- a/components/esp_matter/data_model/esp_matter_event.h +++ b/components/esp_matter/data_model/esp_matter_event.h @@ -279,5 +279,11 @@ event_t *create_push_transport_end(cluster_t *cluster); } // namespace event } // namespace push_av_stream_transport +namespace commodity_price { +namespace event { +event_t *create_price_change(cluster_t *cluster); +} // namespace event +} // namespace commodity_price + } // 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 b0152d35f..77c32dcc4 100644 --- a/components/esp_matter/data_model/esp_matter_feature.cpp +++ b/components/esp_matter/data_model/esp_matter_feature.cpp @@ -4641,5 +4641,28 @@ esp_err_t add(cluster_t *cluster) } /* feature */ } /* commodity_tariff */ +namespace commodity_price { +namespace feature { +namespace forecasting { + +uint32_t get_id() +{ + return static_cast(CommodityPrice::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_price_forecast(cluster, NULL, 0, 0); + return ESP_OK; +} + +} /* forecasting */ + +} /* feature */ +} /* commodity_price */ + } /* 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 71f692c35..f1d693ea1 100644 --- a/components/esp_matter/data_model/esp_matter_feature.h +++ b/components/esp_matter/data_model/esp_matter_feature.h @@ -2073,5 +2073,17 @@ esp_err_t add(cluster_t *cluster); } /* feature */ } /* commodity_tariff */ +namespace commodity_price { +namespace feature { + +namespace forecasting { + +uint32_t get_id(); +esp_err_t add(cluster_t *cluster); +} /* forecasting */ + +} /* feature */ +} /* commodity_price */ + } /* 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 a29cba322..5ba506447 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 @@ -402,6 +402,10 @@ constexpr uint16_t cluster_revision = 1; namespace commodity_tariff { constexpr uint16_t cluster_revision = 1; } // namespace commodity_tariff + +namespace commodity_price { +constexpr uint16_t cluster_revision = 4; +} // namespace commodity_price } // namespace cluster } // namespace esp_matter