mirror of
https://github.com/espressif/esp-matter.git
synced 2026-04-27 19:13:13 +00:00
Merge branch 'feat/add-commodity_price-cluster' into 'main'
Add commodity price cluster See merge request app-frameworks/esp-matter!1356
This commit is contained in:
@@ -5268,5 +5268,34 @@ attribute_t *create_default_randomization_type(cluster_t *cluster, nullable<uint
|
|||||||
} /* attribute */
|
} /* attribute */
|
||||||
} /* commodity_tariff */
|
} /* commodity_tariff */
|
||||||
|
|
||||||
|
namespace commodity_price {
|
||||||
|
namespace attribute {
|
||||||
|
attribute_t *create_tariff_unit(cluster_t *cluster, uint8_t value)
|
||||||
|
{
|
||||||
|
return esp_matter::attribute::create(cluster, CommodityPrice::Attributes::TariffUnit::Id,
|
||||||
|
ATTRIBUTE_FLAG_MANAGED_INTERNALLY, esp_matter_enum8(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
attribute_t *create_currency(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count)
|
||||||
|
{
|
||||||
|
return esp_matter::attribute::create(cluster, CommodityPrice::Attributes::Currency::Id,
|
||||||
|
ATTRIBUTE_FLAG_MANAGED_INTERNALLY | ATTRIBUTE_FLAG_NULLABLE, esp_matter_array(value, length, count));
|
||||||
|
}
|
||||||
|
|
||||||
|
attribute_t *create_current_price(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count)
|
||||||
|
{
|
||||||
|
return esp_matter::attribute::create(cluster, CommodityPrice::Attributes::CurrentPrice::Id,
|
||||||
|
ATTRIBUTE_FLAG_MANAGED_INTERNALLY | ATTRIBUTE_FLAG_NULLABLE, esp_matter_array(value, length, count));
|
||||||
|
}
|
||||||
|
|
||||||
|
attribute_t *create_price_forecast(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count)
|
||||||
|
{
|
||||||
|
return esp_matter::attribute::create(cluster, CommodityPrice::Attributes::PriceForecast::Id,
|
||||||
|
ATTRIBUTE_FLAG_MANAGED_INTERNALLY, esp_matter_array(value, length, count));
|
||||||
|
}
|
||||||
|
|
||||||
|
} /* attribute */
|
||||||
|
} /* commodity_price */
|
||||||
|
|
||||||
} /* cluster */
|
} /* cluster */
|
||||||
} /* esp_matter */
|
} /* esp_matter */
|
||||||
|
|||||||
@@ -1357,5 +1357,14 @@ attribute_t *create_default_randomization_type(cluster_t *cluster, nullable<uint
|
|||||||
} /* attribute */
|
} /* attribute */
|
||||||
} /* commodity_tariff */
|
} /* commodity_tariff */
|
||||||
|
|
||||||
|
namespace commodity_price {
|
||||||
|
namespace attribute {
|
||||||
|
attribute_t *create_tariff_unit(cluster_t *cluster, uint8_t value);
|
||||||
|
attribute_t *create_currency(cluster_t *cluster, uint8_t * value, uint16_t length, uint16_t count);
|
||||||
|
attribute_t *create_current_price(cluster_t *cluster, uint8_t * value, uint16_t length, uint16_t count);
|
||||||
|
attribute_t *create_price_forecast(cluster_t *cluster, uint8_t * value, uint16_t length, uint16_t count);
|
||||||
|
} /* attribute */
|
||||||
|
} /* commodity_price */
|
||||||
|
|
||||||
} /* cluster */
|
} /* cluster */
|
||||||
} /* esp_matter */
|
} /* esp_matter */
|
||||||
|
|||||||
@@ -741,5 +741,26 @@ void add_bounds_cb(cluster_t *cluster)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} /* commodity_tariff */
|
} /* 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 */
|
||||||
} /* cluster */
|
} /* cluster */
|
||||||
} /* esp_matter */
|
} /* esp_matter */
|
||||||
|
|||||||
@@ -53,5 +53,9 @@ void add_bounds_cb(cluster_t *cluster);
|
|||||||
namespace commodity_tariff {
|
namespace commodity_tariff {
|
||||||
void add_bounds_cb(cluster_t *cluster);
|
void add_bounds_cb(cluster_t *cluster);
|
||||||
} /* commodity_tariff */
|
} /* commodity_tariff */
|
||||||
|
|
||||||
|
namespace commodity_price {
|
||||||
|
void add_bounds_cb(cluster_t *cluster);
|
||||||
|
} /* commodity_price */
|
||||||
} /* cluster */
|
} /* cluster */
|
||||||
} /* esp_matter */
|
} /* esp_matter */
|
||||||
|
|||||||
@@ -4419,5 +4419,42 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags)
|
|||||||
|
|
||||||
} /* commodity_tariff */
|
} /* commodity_tariff */
|
||||||
|
|
||||||
|
namespace commodity_price {
|
||||||
|
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, CommodityPrice::Id, flags);
|
||||||
|
VerifyOrReturnValue(cluster, NULL, ESP_LOGE(TAG, "Could not create cluster. cluster_id: 0x%08" PRIX32, CommodityPrice::Id));
|
||||||
|
if (flags & CLUSTER_FLAG_SERVER) {
|
||||||
|
if (config && config->delegate != 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 */
|
} /* cluster */
|
||||||
} /* esp_matter */
|
} /* esp_matter */
|
||||||
|
|||||||
@@ -1048,5 +1048,14 @@ typedef struct config {
|
|||||||
cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags);
|
cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags);
|
||||||
} /* commodity_tariff */
|
} /* 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 */
|
} /* cluster */
|
||||||
} /* esp_matter */
|
} /* esp_matter */
|
||||||
|
|||||||
@@ -3182,5 +3182,34 @@ command_t *create_get_day_entry_response(cluster_t *cluster)
|
|||||||
} /* command */
|
} /* command */
|
||||||
} /* commodity_tariff */
|
} /* 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 */
|
} /* cluster */
|
||||||
} /* esp_matter */
|
} /* esp_matter */
|
||||||
|
|||||||
@@ -601,5 +601,14 @@ command_t *create_get_day_entry_response(cluster_t *cluster);
|
|||||||
} /* command */
|
} /* command */
|
||||||
} /* commodity_tariff */
|
} /* 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 */
|
} /* cluster */
|
||||||
} /* esp_matter */
|
} /* esp_matter */
|
||||||
|
|||||||
@@ -52,6 +52,7 @@
|
|||||||
#include <app/clusters/closure-dimension-server/closure-dimension-server.h>
|
#include <app/clusters/closure-dimension-server/closure-dimension-server.h>
|
||||||
#include <app/clusters/push-av-stream-transport-server/push-av-stream-transport-cluster.h>
|
#include <app/clusters/push-av-stream-transport-server/push-av-stream-transport-cluster.h>
|
||||||
#include <app/clusters/commodity-tariff-server/commodity-tariff-server.h>
|
#include <app/clusters/commodity-tariff-server/commodity-tariff-server.h>
|
||||||
|
#include <app/clusters/commodity-price-server/commodity-price-server.h>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
using namespace chip::app::Clusters;
|
using namespace chip::app::Clusters;
|
||||||
@@ -595,6 +596,16 @@ void CommodityTariffDelegateInitCB(void *delegate, uint16_t endpoint_id)
|
|||||||
commodity_tariff_instance->Init();
|
commodity_tariff_instance->Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CommodityPriceDelegateInitCB(void *delegate, uint16_t endpoint_id)
|
||||||
|
{
|
||||||
|
VerifyOrReturn(delegate != nullptr);
|
||||||
|
CommodityPrice::Delegate *commodity_price_delegate = static_cast<CommodityPrice::Delegate*>(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<CommodityPrice::Feature, uint32_t>(feature_map));
|
||||||
|
commodity_price_instance->Init();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace delegate_cb
|
} // namespace delegate_cb
|
||||||
} // namespace cluster
|
} // namespace cluster
|
||||||
} // namespace esp_matter
|
} // namespace esp_matter
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ void ClosureControlDelegateInitCB(void *delegate, uint16_t endpoint_id);
|
|||||||
void ClosureDimensionDelegateInitCB(void *delegate, uint16_t endpoint_id);
|
void ClosureDimensionDelegateInitCB(void *delegate, uint16_t endpoint_id);
|
||||||
void PushAvStreamTransportDelegateInitCB(void *delegate, uint16_t endpoint_id);
|
void PushAvStreamTransportDelegateInitCB(void *delegate, uint16_t endpoint_id);
|
||||||
void CommodityTariffDelegateInitCB(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 delegate_cb
|
||||||
|
|
||||||
} // namespace cluster
|
} // namespace cluster
|
||||||
|
|||||||
@@ -882,5 +882,15 @@ event_t *create_push_transport_end(cluster_t *cluster)
|
|||||||
} // namespace event
|
} // namespace event
|
||||||
} // namespace push_av_stream_transport
|
} // 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 cluster
|
||||||
} // namespace esp_matter
|
} // namespace esp_matter
|
||||||
|
|||||||
@@ -279,5 +279,11 @@ event_t *create_push_transport_end(cluster_t *cluster);
|
|||||||
} // namespace event
|
} // namespace event
|
||||||
} // namespace push_av_stream_transport
|
} // 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 cluster
|
||||||
} // namespace esp_matter
|
} // namespace esp_matter
|
||||||
|
|||||||
@@ -4778,5 +4778,28 @@ esp_err_t add(cluster_t *cluster)
|
|||||||
} /* feature */
|
} /* feature */
|
||||||
} /* commodity_tariff */
|
} /* commodity_tariff */
|
||||||
|
|
||||||
|
namespace commodity_price {
|
||||||
|
namespace feature {
|
||||||
|
namespace forecasting {
|
||||||
|
|
||||||
|
uint32_t get_id()
|
||||||
|
{
|
||||||
|
return static_cast<uint32_t>(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 */
|
} /* cluster */
|
||||||
} /* esp_matter */
|
} /* esp_matter */
|
||||||
|
|||||||
@@ -2103,5 +2103,17 @@ esp_err_t add(cluster_t *cluster);
|
|||||||
} /* feature */
|
} /* feature */
|
||||||
} /* commodity_tariff */
|
} /* 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 */
|
} /* cluster */
|
||||||
} /* esp_matter */
|
} /* esp_matter */
|
||||||
|
|||||||
@@ -402,6 +402,10 @@ constexpr uint16_t cluster_revision = 1;
|
|||||||
namespace commodity_tariff {
|
namespace commodity_tariff {
|
||||||
constexpr uint16_t cluster_revision = 1;
|
constexpr uint16_t cluster_revision = 1;
|
||||||
} // namespace commodity_tariff
|
} // namespace commodity_tariff
|
||||||
|
|
||||||
|
namespace commodity_price {
|
||||||
|
constexpr uint16_t cluster_revision = 4;
|
||||||
|
} // namespace commodity_price
|
||||||
} // namespace cluster
|
} // namespace cluster
|
||||||
} // namespace esp_matter
|
} // namespace esp_matter
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user