components/esp-matter: Replace conditionals and null checks with CHIP macros in attribute and attribute_utils.

This commit is contained in:
mahesh
2024-07-09 16:23:12 +05:30
parent 785b16cb90
commit 8211f89ffe
2 changed files with 62 additions and 232 deletions
+44 -172
View File
@@ -174,10 +174,7 @@ attribute_t *create_product_id(cluster_t *cluster, uint16_t value)
attribute_t *create_node_label(cluster_t *cluster, char *value, uint16_t length)
{
if (length > k_max_node_label_length) {
ESP_LOGE(TAG, "Could not create attribute, string length out of bound");
return NULL;
}
VerifyOrReturnValue(length <= k_max_node_label_length, NULL, ESP_LOGE(TAG, "Could not create attribute, string length out of bound"));
return esp_matter::attribute::create(cluster, BasicInformation::Attributes::NodeLabel::Id,
ATTRIBUTE_FLAG_WRITABLE | ATTRIBUTE_FLAG_NONVOLATILE,
esp_matter_char_str(value, length), k_max_node_label_length);
@@ -915,10 +912,7 @@ attribute_t *create_product_name(cluster_t *cluster, char *value, uint16_t lengt
attribute_t *create_node_label(cluster_t *cluster, char *value, uint16_t length)
{
if (length > k_max_node_label_length) {
ESP_LOGE(TAG, "Could not create attribute, string length out of bound");
return NULL;
}
VerifyOrReturnValue(length <= k_max_node_label_length, NULL, ESP_LOGE(TAG, "Could not create attribute, string length out of bound"));
return esp_matter::attribute::create(cluster, BridgedDeviceBasicInformation::Attributes::NodeLabel::Id,
ATTRIBUTE_FLAG_WRITABLE | ATTRIBUTE_FLAG_NONVOLATILE,
esp_matter_char_str(value, length), k_max_node_label_length);
@@ -1308,10 +1302,7 @@ attribute_t *create_drift_compensation(cluster_t *cluster, uint8_t value)
attribute_t *create_compensation_text(cluster_t *cluster, char *value, uint16_t length)
{
if (length > k_max_compensation_text_length) {
ESP_LOGE(TAG, "Could not create attribute, string length out of bound");
return NULL;
}
VerifyOrReturnValue(length <= k_max_compensation_text_length, NULL, ESP_LOGE(TAG, "Could not create attribute, string length out of bound"));
return esp_matter::attribute::create(cluster, ColorControl::Attributes::CompensationText::Id, ATTRIBUTE_FLAG_NONE,
esp_matter_char_str(value, length), k_max_compensation_text_length);
}
@@ -2965,10 +2956,8 @@ attribute_t *create_number_of_credentials_supported_per_user(cluster_t *cluster,
attribute_t *create_language(cluster_t *cluster, const char * value, uint16_t length)
{
if (length > k_max_language_length) {
ESP_LOGE(TAG, "Could not create attribute, string size out of bound");
return NULL;
}
VerifyOrReturnValue(length <= k_max_language_length, NULL, ESP_LOGE(TAG, "Could not create attribute, string size out of bound"));
return esp_matter::attribute::create(cluster, DoorLock::Attributes::Language::Id, ATTRIBUTE_FLAG_WRITABLE,
esp_matter_char_str((char *)value, length), k_max_language_length);
}
@@ -2995,10 +2984,7 @@ attribute_t *create_operating_mode(cluster_t *cluster, uint8_t value, uint8_t mi
{
attribute_t *attribute = esp_matter::attribute::create(cluster, DoorLock::Attributes::OperatingMode::Id,
ATTRIBUTE_FLAG_WRITABLE, esp_matter_enum8(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
VerifyOrReturnValue(attribute, NULL, ESP_LOGE(TAG, "Could not create attribute. cluster_id: 0x%08" PRIX32 "'s attribute_id: 0x%08" PRIX32 , cluster::get_id(cluster), DoorLock::Attributes::OperatingMode::Id));
esp_matter::attribute::add_bounds(attribute, esp_matter_enum8(min), esp_matter_enum8(max));
return attribute;
}
@@ -3049,10 +3035,7 @@ attribute_t *create_wrong_code_entry_limit(cluster_t *cluster, uint8_t value)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, DoorLock::Attributes::WrongCodeEntryLimit::Id,
ATTRIBUTE_FLAG_WRITABLE, esp_matter_uint8(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
VerifyOrReturnValue(attribute, NULL, ESP_LOGE(TAG, "Could not create attribute. cluster_id: 0x%08" PRIX32 "'s attribute_id: 0x%08" PRIX32 , cluster::get_id(cluster), DoorLock::Attributes::WrongCodeEntryLimit::Id));
esp_matter::attribute::add_bounds(attribute, esp_matter_uint8(1), esp_matter_uint8(255));
return attribute;
}
@@ -3061,10 +3044,7 @@ attribute_t *create_user_code_temporary_disable_time(cluster_t *cluster, uint8_t
{
attribute_t *attribute = esp_matter::attribute::create(cluster, DoorLock::Attributes::UserCodeTemporaryDisableTime::Id,
ATTRIBUTE_FLAG_WRITABLE, esp_matter_uint8(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
VerifyOrReturnValue(attribute, NULL, ESP_LOGE(TAG, "Could not create attribute. cluster_id: 0x%08" PRIX32 "'s attribute_id: 0x%08" PRIX32 , cluster::get_id(cluster), DoorLock::Attributes::UserCodeTemporaryDisableTime::Id));
esp_matter::attribute::add_bounds(attribute, esp_matter_uint8(1), esp_matter_uint8(255));
return attribute;
}
@@ -3085,10 +3065,7 @@ attribute_t *create_expiring_user_timeout(cluster_t *cluster, uint16_t value)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, DoorLock::Attributes::ExpiringUserTimeout::Id,
ATTRIBUTE_FLAG_WRITABLE, esp_matter_uint16(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
VerifyOrReturnValue(attribute, NULL, ESP_LOGE(TAG, "Could not create attribute. cluster_id: 0x%08" PRIX32 "'s attribute_id: 0x%08" PRIX32 , cluster::get_id(cluster), DoorLock::Attributes::ExpiringUserTimeout::Id));
esp_matter::attribute::add_bounds(attribute, esp_matter_uint16(1), esp_matter_uint16(2880));
return attribute;
}
@@ -3412,10 +3389,7 @@ namespace attribute {
attribute_t *create_active_locale(cluster_t *cluster, char *value, uint16_t length)
{
if (length > k_max_active_locale_length) {
ESP_LOGE(TAG, "Could not create attribute, string length out of bound");
return NULL;
}
VerifyOrReturnValue(length <= k_max_active_locale_length, NULL, ESP_LOGE(TAG, "Could not create attribute, string length out of bound"));
return esp_matter::attribute::create(cluster, LocalizationConfiguration::Attributes::ActiveLocale::Id,
ATTRIBUTE_FLAG_WRITABLE | ATTRIBUTE_FLAG_NONVOLATILE,
esp_matter_char_str(value, length), k_max_active_locale_length);
@@ -3474,10 +3448,7 @@ namespace attribute {
attribute_t *create_illuminance_measured_value(cluster_t *cluster, nullable<uint16_t> value, nullable<uint16_t> min, nullable<uint16_t> max)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, IlluminanceMeasurement::Attributes::MeasuredValue::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_uint16(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
VerifyOrReturnValue(attribute, NULL, ESP_LOGE(TAG, "Could not create attribute. cluster_id: 0x%08" PRIX32 "'s attribute_id: 0x%08" PRIX32 , cluster::get_id(cluster), IlluminanceMeasurement::Attributes::MeasuredValue::Id));
esp_matter::attribute::add_bounds(attribute, esp_matter_nullable_uint16(min), esp_matter_nullable_uint16(max));
return attribute;
}
@@ -3485,10 +3456,7 @@ attribute_t *create_illuminance_measured_value(cluster_t *cluster, nullable<uint
attribute_t *create_illuminance_min_measured_value(cluster_t *cluster, nullable<uint16_t> value, nullable<uint16_t> min, nullable<uint16_t> max)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, IlluminanceMeasurement::Attributes::MinMeasuredValue::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_uint16(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
VerifyOrReturnValue(attribute, NULL, ESP_LOGE(TAG, "Could not create attribute. cluster_id: 0x%08" PRIX32 "'s attribute_id: 0x%08" PRIX32 , cluster::get_id(cluster), IlluminanceMeasurement::Attributes::MinMeasuredValue::Id));
esp_matter::attribute::add_bounds(attribute, esp_matter_nullable_uint16(min), esp_matter_nullable_uint16(max));
return attribute;
}
@@ -3496,10 +3464,7 @@ attribute_t *create_illuminance_min_measured_value(cluster_t *cluster, nullable<
attribute_t *create_illuminance_max_measured_value(cluster_t *cluster, nullable<uint16_t> value, nullable<uint16_t> min, nullable<uint16_t> max)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, IlluminanceMeasurement::Attributes::MaxMeasuredValue::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_uint16(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
VerifyOrReturnValue(attribute, NULL, ESP_LOGE(TAG, "Could not create attribute. cluster_id: 0x%08" PRIX32 "'s attribute_id: 0x%08" PRIX32 , cluster::get_id(cluster), IlluminanceMeasurement::Attributes::MaxMeasuredValue::Id));
esp_matter::attribute::add_bounds(attribute, esp_matter_nullable_uint16(min), esp_matter_nullable_uint16(max));
return attribute;
}
@@ -3507,10 +3472,7 @@ attribute_t *create_illuminance_max_measured_value(cluster_t *cluster, nullable<
attribute_t *create_illuminance_tolerance(cluster_t *cluster, uint16_t value, uint16_t min, uint16_t max)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, IlluminanceMeasurement::Attributes::Tolerance::Id, ATTRIBUTE_FLAG_NONE, esp_matter_uint16(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
VerifyOrReturnValue(attribute, NULL, ESP_LOGE(TAG, "Could not create attribute. cluster_id: 0x%08" PRIX32 "'s attribute_id: 0x%08" PRIX32 , cluster::get_id(cluster), IlluminanceMeasurement::Attributes::Tolerance::Id));
esp_matter::attribute::add_bounds(attribute, esp_matter_uint16(min), esp_matter_uint16(max));
return attribute;
}
@@ -3518,10 +3480,7 @@ attribute_t *create_illuminance_tolerance(cluster_t *cluster, uint16_t value, ui
attribute_t *create_illuminance_light_sensor_type(cluster_t *cluster, nullable<uint8_t> value, nullable<uint8_t> min, nullable<uint8_t> max)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, IlluminanceMeasurement::Attributes::LightSensorType::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_enum8(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
VerifyOrReturnValue(attribute, NULL, ESP_LOGE(TAG, "Could not create attribute. cluster_id: 0x%08" PRIX32 "'s attribute_id: 0x%08" PRIX32 , cluster::get_id(cluster), IlluminanceMeasurement::Attributes::LightSensorType::Id));
esp_matter::attribute::add_bounds(attribute, esp_matter_nullable_enum8(min), esp_matter_nullable_enum8(max));
return attribute;
}
@@ -3550,10 +3509,7 @@ attribute_t *create_pressure_max_measured_value(cluster_t *cluster, nullable<int
attribute_t *create_pressure_tolerance(cluster_t *cluster, uint16_t value, uint16_t min, uint16_t max)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, PressureMeasurement::Attributes::Tolerance::Id, ATTRIBUTE_FLAG_NONE, esp_matter_uint16(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
VerifyOrReturnValue(attribute, NULL, ESP_LOGE(TAG, "Could not create attribute. cluster_id: 0x%08" PRIX32 "'s attribute_id: 0x%08" PRIX32 , cluster::get_id(cluster), PressureMeasurement::Attributes::Tolerance::Id));
esp_matter::attribute::add_bounds(attribute, esp_matter_uint16(min), esp_matter_uint16(max));
return attribute;
}
@@ -3576,10 +3532,7 @@ attribute_t *create_pressure_max_scaled_value(cluster_t *cluster, nullable<int16
attribute_t *create_pressure_scaled_tolerance(cluster_t *cluster, uint16_t value, uint16_t min, uint16_t max)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, PressureMeasurement::Attributes::ScaledTolerance::Id, ATTRIBUTE_FLAG_NONE, esp_matter_uint16(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
VerifyOrReturnValue(attribute, NULL, ESP_LOGE(TAG, "Could not create attribute. cluster_id: 0x%08" PRIX32 "'s attribute_id: 0x%08" PRIX32 , cluster::get_id(cluster), PressureMeasurement::Attributes::ScaledTolerance::Id));
esp_matter::attribute::add_bounds(attribute, esp_matter_uint16(min), esp_matter_uint16(max));
return attribute;
}
@@ -3613,10 +3566,7 @@ attribute_t *create_flow_max_measured_value(cluster_t *cluster, nullable<uint16_
attribute_t *create_flow_tolerance(cluster_t *cluster, uint16_t value, uint16_t min, uint16_t max)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, FlowMeasurement::Attributes::Tolerance::Id, ATTRIBUTE_FLAG_NONE, esp_matter_uint16(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
VerifyOrReturnValue(attribute, NULL, ESP_LOGE(TAG, "Could not create attribute. cluster_id: 0x%08" PRIX32 "'s attribute_id: 0x%08" PRIX32 , cluster::get_id(cluster), FlowMeasurement::Attributes::Tolerance::Id));
esp_matter::attribute::add_bounds(attribute, esp_matter_uint16(min), esp_matter_uint16(max));
return attribute;
}
@@ -3748,10 +3698,7 @@ namespace attribute {
attribute_t *create_mode_select_description(cluster_t *cluster, const char * value, uint16_t length)
{
if (length > k_max_mode_select_description_length) {
ESP_LOGE(TAG, "Could not create attribute, string length out of bound");
return NULL;
}
VerifyOrReturnValue(length <= k_max_mode_select_description_length, NULL, ESP_LOGE(TAG, "Could not create attribute, string length out of bound"));
return esp_matter::attribute::create(cluster, ModeSelect::Attributes::Description::Id, ATTRIBUTE_FLAG_NONE,
esp_matter_char_str((char *)value, length),
k_max_mode_select_description_length);
@@ -3796,20 +3743,14 @@ attribute_t *create_status(cluster_t *cluster, uint8_t value)
attribute_t *create_order(cluster_t *cluster, uint8_t value, uint8_t min, uint8_t max)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, PowerSource::Attributes::Order::Id, ATTRIBUTE_FLAG_NONVOLATILE, esp_matter_uint8(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
VerifyOrReturnValue(attribute, NULL, ESP_LOGE(TAG, "Could not create attribute. cluster_id: 0x%08" PRIX32 "'s attribute_id: 0x%08" PRIX32 , cluster::get_id(cluster), PowerSource::Attributes::Order::Id));
esp_matter::attribute::add_bounds(attribute, esp_matter_uint8(min), esp_matter_uint8(max));
return attribute;
}
attribute_t *create_description(cluster_t *cluster, const char * value, uint16_t length)
{
if (length > k_max_description_length) {
ESP_LOGE(TAG, "Could not create attribute, string length out of bound");
return NULL;
}
VerifyOrReturnValue(length <= k_max_description_length, NULL, ESP_LOGE(TAG, "Could not create attribute, string length out of bound"));
return esp_matter::attribute::create(cluster, PowerSource::Attributes::Description::Id, ATTRIBUTE_FLAG_NONE,
esp_matter_char_str((char *)value, length), k_max_description_length);
}
@@ -3817,10 +3758,7 @@ attribute_t *create_description(cluster_t *cluster, const char * value, uint16_t
attribute_t *create_wired_assessed_input_voltage(cluster_t *cluster, nullable<uint32_t> value, nullable<uint32_t> min, nullable<uint32_t> max)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, PowerSource::Attributes::WiredAssessedInputVoltage::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_uint32(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
VerifyOrReturnValue(attribute, NULL, ESP_LOGE(TAG, "Could not create attribute. cluster_id: 0x%08" PRIX32 "'s attribute_id: 0x%08" PRIX32 , cluster::get_id(cluster), PowerSource::Attributes::WiredAssessedInputVoltage::Id));
esp_matter::attribute::add_bounds(attribute, esp_matter_nullable_uint32(min), esp_matter_nullable_uint32(max));
return attribute;
}
@@ -3828,10 +3766,7 @@ attribute_t *create_wired_assessed_input_voltage(cluster_t *cluster, nullable<ui
attribute_t *create_wired_assessed_input_frequency(cluster_t *cluster, nullable<uint16_t> value, nullable<uint16_t> min, nullable<uint16_t> max)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, PowerSource::Attributes::WiredAssessedInputFrequency::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_uint16(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
VerifyOrReturnValue(attribute, NULL, ESP_LOGE(TAG, "Could not create attribute. cluster_id: 0x%08" PRIX32 "'s attribute_id: 0x%08" PRIX32 , cluster::get_id(cluster), PowerSource::Attributes::WiredAssessedInputFrequency::Id));
esp_matter::attribute::add_bounds(attribute, esp_matter_nullable_uint16(min), esp_matter_nullable_uint16(max));
return attribute;
}
@@ -3844,10 +3779,7 @@ attribute_t *create_wired_current_type(cluster_t *cluster, const uint8_t value)
attribute_t *create_wired_assessed_current(cluster_t *cluster, nullable<uint32_t> value, nullable<uint32_t> min, nullable<uint32_t> max)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, PowerSource::Attributes::WiredAssessedCurrent::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_uint32(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
VerifyOrReturnValue(attribute, NULL, ESP_LOGE(TAG, "Could not create attribute. cluster_id: 0x%08" PRIX32 "'s attribute_id: 0x%08" PRIX32 , cluster::get_id(cluster), PowerSource::Attributes::WiredAssessedCurrent::Id));
esp_matter::attribute::add_bounds(attribute, esp_matter_nullable_uint32(min), esp_matter_nullable_uint32(max));
return attribute;
}
@@ -3855,10 +3787,7 @@ attribute_t *create_wired_assessed_current(cluster_t *cluster, nullable<uint32_t
attribute_t *create_wired_nominal_voltage(cluster_t *cluster, const uint32_t value, uint32_t min, uint32_t max)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, PowerSource::Attributes::WiredNominalVoltage::Id, ATTRIBUTE_FLAG_NONE, esp_matter_uint32(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
VerifyOrReturnValue(attribute, NULL, ESP_LOGE(TAG, "Could not create attribute. cluster_id: 0x%08" PRIX32 "'s attribute_id: 0x%08" PRIX32 , cluster::get_id(cluster), PowerSource::Attributes::WiredNominalVoltage::Id));
esp_matter::attribute::add_bounds(attribute, esp_matter_uint32(min), esp_matter_uint32(max));
return attribute;
}
@@ -3866,10 +3795,7 @@ attribute_t *create_wired_nominal_voltage(cluster_t *cluster, const uint32_t val
attribute_t *create_wired_maximum_current(cluster_t *cluster, const uint32_t value, uint32_t min, uint32_t max)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, PowerSource::Attributes::WiredMaximumCurrent::Id, ATTRIBUTE_FLAG_NONE, esp_matter_uint32(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
VerifyOrReturnValue(attribute, NULL, ESP_LOGE(TAG, "Could not create attribute. cluster_id: 0x%08" PRIX32 "'s attribute_id: 0x%08" PRIX32 , cluster::get_id(cluster), PowerSource::Attributes::WiredMaximumCurrent::Id));
esp_matter::attribute::add_bounds(attribute, esp_matter_uint32(min), esp_matter_uint32(max));
return attribute;
}
@@ -3881,20 +3807,14 @@ attribute_t *create_wired_present(cluster_t *cluster, bool value)
attribute_t *create_active_wired_faults(cluster_t *cluster, uint8_t * value, uint16_t length, uint16_t count)
{
if (count > k_max_fault_count) {
ESP_LOGE(TAG, "Could not create attribute, list out of bound");
return NULL;
}
VerifyOrReturnValue(count <= k_max_fault_count, NULL, ESP_LOGE(TAG, "Could not create attribute, list out of bound"));
return esp_matter::attribute::create(cluster, PowerSource::Attributes::ActiveWiredFaults::Id, ATTRIBUTE_FLAG_NONE, esp_matter_array(value, length, count));
}
attribute_t *create_bat_voltage(cluster_t *cluster, nullable<uint32_t> value, nullable<uint32_t> min, nullable<uint32_t> max)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, PowerSource::Attributes::BatVoltage::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_uint32(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
VerifyOrReturnValue(attribute, NULL, ESP_LOGE(TAG, "Could not create attribute. cluster_id: 0x%08" PRIX32 "'s attribute_id: 0x%08" PRIX32 , cluster::get_id(cluster), PowerSource::Attributes::BatVoltage::Id));
esp_matter::attribute::add_bounds(attribute, esp_matter_nullable_uint32(min), esp_matter_nullable_uint32(max));
return attribute;
}
@@ -3902,10 +3822,7 @@ attribute_t *create_bat_voltage(cluster_t *cluster, nullable<uint32_t> value, nu
attribute_t *create_bat_percent_remaining(cluster_t *cluster, nullable<uint8_t> value, nullable<uint8_t> min, nullable<uint8_t> max)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, PowerSource::Attributes::BatPercentRemaining::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_uint8(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
VerifyOrReturnValue(attribute, NULL, ESP_LOGE(TAG, "Could not create attribute. cluster_id: 0x%08" PRIX32 "'s attribute_id: 0x%08" PRIX32 , cluster::get_id(cluster), PowerSource::Attributes::BatPercentRemaining::Id));
esp_matter::attribute::add_bounds(attribute, esp_matter_nullable_uint8(min), esp_matter_nullable_uint8(max));
return attribute;
}
@@ -3913,10 +3830,7 @@ attribute_t *create_bat_percent_remaining(cluster_t *cluster, nullable<uint8_t>
attribute_t *create_bat_time_remaining(cluster_t *cluster, nullable< uint32_t> value, nullable<uint32_t> min, nullable<uint32_t> max)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, PowerSource::Attributes::BatTimeRemaining::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_uint32(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
VerifyOrReturnValue(attribute, NULL, ESP_LOGE(TAG, "Could not create attribute. cluster_id: 0x%08" PRIX32 "'s attribute_id: 0x%08" PRIX32 , cluster::get_id(cluster), PowerSource::Attributes::BatTimeRemaining::Id));
esp_matter::attribute::add_bounds(attribute, esp_matter_nullable_uint32(min), esp_matter_nullable_uint32(max));
return attribute;
}
@@ -3943,19 +3857,13 @@ attribute_t *create_bat_present(cluster_t *cluster, bool value)
attribute_t *create_active_bat_faults(cluster_t *cluster, uint8_t * value, uint16_t length, uint16_t count)
{
if (count > k_max_fault_count) {
ESP_LOGE(TAG, "Could not create attribute, list out of bound");
return NULL;
}
VerifyOrReturnValue(count <= k_max_fault_count, NULL, ESP_LOGE(TAG, "Could not create attribute, list out of bound"));
return esp_matter::attribute::create(cluster, PowerSource::Attributes::ActiveBatFaults::Id, ATTRIBUTE_FLAG_NONE, esp_matter_array(value, length, count));
}
attribute_t *create_bat_replacement_description(cluster_t *cluster, const char * value, uint16_t length)
{
if (length > k_max_bat_replacement_description_length) {
ESP_LOGE(TAG, "Could not create attribute, string size out of bound");
return NULL;
}
VerifyOrReturnValue(length <= k_max_bat_replacement_description_length, NULL, ESP_LOGE(TAG, "Could not create attribute, string size out of bound"));
return esp_matter::attribute::create(cluster, PowerSource::Attributes::BatReplacementDescription::Id,
ATTRIBUTE_FLAG_NONE, esp_matter_char_str((char *)value, length),
k_max_bat_replacement_description_length);
@@ -3964,39 +3872,27 @@ attribute_t *create_bat_replacement_description(cluster_t *cluster, const char *
attribute_t *create_bat_common_designation(cluster_t *cluster, const uint8_t value, uint8_t min, uint8_t max)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, PowerSource::Attributes::BatCommonDesignation::Id, ATTRIBUTE_FLAG_NONE, esp_matter_enum8(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
VerifyOrReturnValue(attribute, NULL, ESP_LOGE(TAG, "Could not create attribute. cluster_id: 0x%08" PRIX32 "'s attribute_id: 0x%08" PRIX32 , cluster::get_id(cluster), PowerSource::Attributes::BatCommonDesignation::Id));
esp_matter::attribute::add_bounds(attribute, esp_matter_enum8(min), esp_matter_enum8(max));
return attribute;
}
attribute_t *create_bat_ansi_designation(cluster_t *cluster, const char * value, uint16_t length)
{
if (length > k_max_designation_count) {
ESP_LOGE(TAG, "Could not create attribute, string size out of bound");
return NULL;
}
VerifyOrReturnValue(length <= k_max_designation_count, NULL, ESP_LOGE(TAG, "Could not create attribute, string size out of bound"));
return esp_matter::attribute::create(cluster, PowerSource::Attributes::BatANSIDesignation::Id, ATTRIBUTE_FLAG_NONE, esp_matter_char_str((char *)value, length), k_max_designation_count);
}
attribute_t *create_bat_iec_designation(cluster_t *cluster, const char * value, uint16_t length)
{
if (length > k_max_designation_count) {
ESP_LOGE(TAG, "Could not create attribute, string size out of bound");
return NULL;
}
VerifyOrReturnValue(length <= k_max_designation_count, NULL, ESP_LOGE(TAG, "Could not create attribute, string size out of bound"));
return esp_matter::attribute::create(cluster, PowerSource::Attributes::BatIECDesignation::Id, ATTRIBUTE_FLAG_NONE, esp_matter_char_str((char *)value, length), k_max_designation_count);
}
attribute_t *create_bat_approved_chemistry(cluster_t *cluster, const uint8_t value, uint8_t min, uint8_t max)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, PowerSource::Attributes::BatApprovedChemistry::Id, ATTRIBUTE_FLAG_NONE, esp_matter_enum8(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
VerifyOrReturnValue(attribute, NULL, ESP_LOGE(TAG, "Could not create attribute. cluster_id: 0x%08" PRIX32 "'s attribute_id: 0x%08" PRIX32 , cluster::get_id(cluster), PowerSource::Attributes::BatApprovedChemistry::Id));
esp_matter::attribute::add_bounds(attribute, esp_matter_enum8(min), esp_matter_enum8(max));
return attribute;
}
@@ -4004,10 +3900,7 @@ attribute_t *create_bat_approved_chemistry(cluster_t *cluster, const uint8_t val
attribute_t *create_bat_capacity(cluster_t *cluster, const uint32_t value, uint32_t min, uint32_t max)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, PowerSource::Attributes::BatCapacity::Id, ATTRIBUTE_FLAG_NONE, esp_matter_uint32(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
VerifyOrReturnValue(attribute, NULL, ESP_LOGE(TAG, "Could not create attribute. cluster_id: 0x%08" PRIX32 "'s attribute_id: 0x%08" PRIX32 , cluster::get_id(cluster), PowerSource::Attributes::BatCapacity::Id));
esp_matter::attribute::add_bounds(attribute, esp_matter_uint32(min), esp_matter_uint32(max));
return attribute;
}
@@ -4015,10 +3908,7 @@ attribute_t *create_bat_capacity(cluster_t *cluster, const uint32_t value, uint3
attribute_t *create_bat_quantity(cluster_t *cluster, const uint8_t value, uint8_t min, uint8_t max)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, PowerSource::Attributes::BatQuantity::Id, ATTRIBUTE_FLAG_NONE, esp_matter_uint8(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
VerifyOrReturnValue(attribute, NULL, ESP_LOGE(TAG, "Could not create attribute. cluster_id: 0x%08" PRIX32 "'s attribute_id: 0x%08" PRIX32 , cluster::get_id(cluster), PowerSource::Attributes::BatQuantity::Id));
esp_matter::attribute::add_bounds(attribute, esp_matter_uint8(min), esp_matter_uint8(max));
return attribute;
}
@@ -4031,10 +3921,7 @@ attribute_t *create_bat_charge_state(cluster_t *cluster, uint8_t value)
attribute_t *create_bat_time_to_full_charge(cluster_t *cluster, nullable<uint32_t> value, nullable<uint32_t> min, nullable<uint32_t> max)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, PowerSource::Attributes::BatTimeToFullCharge::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_uint32(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
VerifyOrReturnValue(attribute, NULL, ESP_LOGE(TAG, "Could not create attribute. cluster_id: 0x%08" PRIX32 "'s attribute_id: 0x%08" PRIX32 , cluster::get_id(cluster), PowerSource::Attributes::BatTimeToFullCharge::Id));
esp_matter::attribute::add_bounds(attribute, esp_matter_nullable_uint32(min), esp_matter_nullable_uint32(max));
return attribute;
}
@@ -4047,20 +3934,14 @@ attribute_t *create_bat_functional_while_charging(cluster_t *cluster, bool value
attribute_t *create_bat_charging_current(cluster_t *cluster, nullable<uint32_t> value, nullable<uint32_t> min, nullable<uint32_t> max)
{
attribute_t *attribute = esp_matter::attribute::create(cluster, PowerSource::Attributes::BatChargingCurrent::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_uint32(value));
if (!attribute) {
ESP_LOGE(TAG, "Could not create attribute");
return NULL;
}
VerifyOrReturnValue(attribute, NULL, ESP_LOGE(TAG, "Could not create attribute. cluster_id: 0x%08" PRIX32 "'s attribute_id: 0x%08" PRIX32 , cluster::get_id(cluster), PowerSource::Attributes::BatChargingCurrent::Id));
esp_matter::attribute::add_bounds(attribute, esp_matter_nullable_uint32(min), esp_matter_nullable_uint32(max));
return attribute;
}
attribute_t *create_active_bat_charge_faults(cluster_t *cluster, uint8_t * value, uint16_t length, uint16_t count)
{
if (count > k_max_charge_faults_count) {
ESP_LOGE(TAG, "Could not create attribute, list out of bound");
return NULL;
}
VerifyOrReturnValue(count <= k_max_charge_faults_count, NULL, ESP_LOGE(TAG, "Could not create attribute, list out of bound"));
return esp_matter::attribute::create(cluster, PowerSource::Attributes::ActiveBatChargeFaults::Id, ATTRIBUTE_FLAG_NONE, esp_matter_array(value, length, count));
}
@@ -4096,10 +3977,7 @@ attribute_t *create_selected_temperature_level(cluster_t *cluster, uint8_t value
attribute_t *create_supported_temperature_levels(cluster_t *cluster, uint8_t * value, uint16_t length, uint16_t count)
{
if (count > k_max_temp_level_count) {
ESP_LOGE(TAG, "Could not create attribute, list out of bound");
return NULL;
}
VerifyOrReturnValue(count <= k_max_temp_level_count, NULL, ESP_LOGE(TAG, "Could not create attribute, list out of bound"));
return esp_matter::attribute::create(cluster, TemperatureControl::Attributes::SupportedTemperatureLevels::Id, ATTRIBUTE_FLAG_NONE, esp_matter_array((uint8_t*)value, length, count));
}
@@ -4589,10 +4467,7 @@ namespace application_basic {
namespace attribute {
attribute_t *create_vendor_name(cluster_t *cluster, char *value, uint16_t length)
{
if (length > k_max_vendor_name_length) {
ESP_LOGE(TAG, "Could not create attribute, string length out of bound");
return NULL;
}
VerifyOrReturnValue(length <= k_max_vendor_name_length, NULL, ESP_LOGE(TAG, "Could not create attribute, string length out of bound"));
return esp_matter::attribute::create(cluster, ApplicationBasic::Attributes::VendorName::Id, ATTRIBUTE_FLAG_NONE,
esp_matter_char_str(value, length), k_max_vendor_name_length);
}
@@ -4629,10 +4504,7 @@ attribute_t *create_status(cluster_t *cluster, uint8_t value)
attribute_t *create_application_version(cluster_t *cluster, char *value, uint16_t length)
{
if (length > k_max_application_version_length) {
ESP_LOGE(TAG, "Could not create attribute, string length out of bound");
return NULL;
}
VerifyOrReturnValue(length <= k_max_application_version_length, NULL, ESP_LOGE(TAG, "Could not create attribute, string length out of bound"));
return esp_matter::attribute::create(cluster, ApplicationBasic::Attributes::ApplicationVersion::Id,
ATTRIBUTE_FLAG_NONE, esp_matter_char_str(value, length),
k_max_application_version_length);
@@ -525,10 +525,7 @@ static esp_matter::console::engine attribute_console;
static esp_err_t console_set_handler(int argc, char **argv)
{
if (argc < 4) {
ESP_LOGE(TAG, "The arguments for this command is invalid");
return ESP_ERR_INVALID_ARG;
}
VerifyOrReturnError(argc >= 4, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "The arguments for this command is invalid"));
uint16_t endpoint_id = strtoul((const char *)&argv[0][2], NULL, 16);
uint32_t cluster_id = strtoul((const char *)&argv[1][2], NULL, 16);
@@ -537,10 +534,7 @@ static esp_err_t console_set_handler(int argc, char **argv)
/* Get type from matter_attribute */
const EmberAfAttributeMetadata *matter_attribute = emberAfLocateAttributeMetadata(endpoint_id, cluster_id,
attribute_id);
if (!matter_attribute) {
ESP_LOGE(TAG, "Matter attribute not found");
return ESP_ERR_INVALID_ARG;
}
VerifyOrReturnError(matter_attribute, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Matter attribute not found"));
/* Use the type to create the val and then update te attribute */
esp_matter_val_type_t type = get_val_type_from_attribute_type(matter_attribute->attributeType);
@@ -731,10 +725,7 @@ static esp_err_t console_set_handler(int argc, char **argv)
static esp_err_t console_get_handler(int argc, char **argv)
{
if (argc < 3) {
ESP_LOGE(TAG, "The arguments for this command is invalid");
return ESP_ERR_INVALID_ARG;
}
VerifyOrReturnError(argc >= 3, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "The arguments for this command is invalid"));
uint16_t endpoint_id = strtoul((const char *)&argv[0][2], NULL, 16);
uint32_t cluster_id = strtoul((const char *)&argv[1][2], NULL, 16);
uint32_t attribute_id = strtoul((const char *)&argv[2][2], NULL, 16);
@@ -742,10 +733,7 @@ static esp_err_t console_get_handler(int argc, char **argv)
/* Get type from matter_attribute */
const EmberAfAttributeMetadata *matter_attribute = emberAfLocateAttributeMetadata(endpoint_id, cluster_id,
attribute_id);
if (!matter_attribute) {
ESP_LOGE(TAG, "Matter attribute not found");
return ESP_ERR_INVALID_ARG;
}
VerifyOrReturnError(matter_attribute, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Matter attribute not found"));
/* Use the type to read the raw value and then print */
esp_matter_val_type_t type = get_val_type_from_attribute_type(matter_attribute->attributeType);
@@ -973,19 +961,14 @@ static esp_err_t console_get_handler(int argc, char **argv)
static esp_err_t console_dispatch(int argc, char **argv)
{
if (argc <= 0) {
attribute_console.for_each_command(esp_matter::console::print_description, NULL);
return ESP_OK;
}
VerifyOrReturnError(argc > 0, ESP_OK, attribute_console.for_each_command(esp_matter::console::print_description, NULL));
return attribute_console.exec_command(argc, argv);
}
static void register_console_commands()
{
static bool init_done = false;
if (init_done) {
return;
}
VerifyOrReturn(!init_done);
static const esp_matter::console::command_t command = {
.name = "attribute",
.description = "This can be used to simulate on-device control. ",
@@ -1888,11 +1871,8 @@ esp_err_t get_attr_val_from_data(esp_matter_attr_val_t *val, EmberAfAttributeTyp
void val_print(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val, bool is_read)
{
char action = (is_read) ? 'R' :'W';
if (val_is_null(val)) {
ESP_LOGI(TAG, "********** %c : Endpoint 0x%04" PRIX16 "'s Cluster 0x%08" PRIX32 "'s Attribute 0x%08" PRIX32 " is null **********", action,
endpoint_id, cluster_id, attribute_id);
return;
}
VerifyOrReturn(!val_is_null(val), ESP_LOGI(TAG, "********** %c : Endpoint 0x%04" PRIX16 "'s Cluster 0x%08" PRIX32 "'s Attribute 0x%08" PRIX32 " is null **********", action,
endpoint_id, cluster_id, attribute_id));
if (val->type == ESP_MATTER_VAL_TYPE_BOOLEAN) {
ESP_LOGI(TAG, "********** %c : Endpoint 0x%04" PRIX16 "'s Cluster 0x%08" PRIX32 "'s Attribute 0x%08" PRIX32 " is %d **********", action,
@@ -1953,10 +1933,7 @@ esp_err_t get_val_raw(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attrib
{
/* Take lock if not already taken */
lock::status_t lock_status = lock::chip_stack_lock(portMAX_DELAY);
if (lock_status == lock::FAILED) {
ESP_LOGE(TAG, "Could not get task context");
return ESP_FAIL;
}
VerifyOrReturnError(lock_status != lock::FAILED, ESP_FAIL, ESP_LOGE(TAG, "Could not get task context"));
esp_err_t err = ESP_OK;
Status status = emberAfReadAttribute(endpoint_id, cluster_id, attribute_id, value, attribute_size);
@@ -1975,10 +1952,7 @@ esp_err_t update(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_i
{
/* Take lock if not already taken */
lock::status_t lock_status = lock::chip_stack_lock(portMAX_DELAY);
if (lock_status == lock::FAILED) {
ESP_LOGE(TAG, "Could not get task context");
return ESP_FAIL;
}
VerifyOrReturnError(lock_status != lock::FAILED, ESP_FAIL, ESP_LOGE(TAG, "Could not get task context"));
/* Get size */
EmberAfAttributeType attribute_type = 0;
@@ -2021,10 +1995,7 @@ esp_err_t report(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_i
{
/* Take lock if not already taken */
lock::status_t lock_status = lock::chip_stack_lock(portMAX_DELAY);
if (lock_status == lock::FAILED) {
ESP_LOGE(TAG, "Could not get task context");
return ESP_FAIL;
}
VerifyOrReturnError(lock_status != lock::FAILED, ESP_FAIL, ESP_LOGE(TAG, "Could not get task context"));
/* Get attribute */
node_t *node = node::get();
@@ -2081,9 +2052,7 @@ Status MatterPreAttributeChangeCallback(const chip::app::ConcreteAttributePath &
/* Callback to application */
esp_err_t err = execute_callback(attribute::PRE_UPDATE, endpoint_id, cluster_id, attribute_id, &val);
if (err != ESP_OK) {
return Status::Failure;
}
VerifyOrReturnValue(err == ESP_OK, Status::Failure);
return Status::Success;
}
@@ -2109,9 +2078,7 @@ Status emberAfExternalAttributeReadCallback(EndpointId endpoint_id, ClusterId cl
/* Get value */
uint32_t attribute_id = matter_attribute->attributeId;
node_t *node = node::get();
if (!node) {
return Status::Failure;
}
VerifyOrReturnError(node, Status::Failure);
endpoint_t *endpoint = endpoint::get(node, endpoint_id);
cluster_t *cluster = cluster::get(endpoint, cluster_id);
attribute_t *attribute = attribute::get(cluster, attribute_id);
@@ -2121,9 +2088,7 @@ Status emberAfExternalAttributeReadCallback(EndpointId endpoint_id, ClusterId cl
if (flags & ATTRIBUTE_FLAG_OVERRIDE) {
esp_err_t err = execute_override_callback(attribute, attribute::READ, endpoint_id, cluster_id, attribute_id,
&val);
if (err != ESP_OK) {
return Status::Failure;
}
VerifyOrReturnValue(err == ESP_OK, Status::Failure);
} else {
attribute::get_val(attribute, &val);
}
@@ -2134,11 +2099,8 @@ Status emberAfExternalAttributeReadCallback(EndpointId endpoint_id, ClusterId cl
/* Get size */
uint16_t attribute_size = 0;
attribute::get_data_from_attr_val(&val, NULL, &attribute_size, NULL);
if (attribute_size > max_read_length) {
ESP_LOGE(TAG, "Insufficient space for reading Endpoint 0x%04" PRIX16 "'s Cluster 0x%08" PRIX32 "'s Attribute 0x%08" PRIX32
": required: %" PRIu16 ", max: %" PRIu16 "", endpoint_id, cluster_id, attribute_id, attribute_size, max_read_length);
return Status::ResourceExhausted;
}
VerifyOrReturnValue(attribute_size <= max_read_length, Status::ResourceExhausted, ESP_LOGE(TAG, "Insufficient space for reading Endpoint 0x%04" PRIX16 "'s Cluster 0x%08" PRIX32 "'s Attribute 0x%08" PRIX32
": required: %" PRIu16 ", max: %" PRIu16 "", endpoint_id, cluster_id, attribute_id, attribute_size, max_read_length));
/* Assign value */
attribute::get_data_from_attr_val(&val, NULL, &attribute_size, buffer);
@@ -2151,9 +2113,7 @@ Status emberAfExternalAttributeWriteCallback(EndpointId endpoint_id, ClusterId c
/* Get value */
uint32_t attribute_id = matter_attribute->attributeId;
node_t *node = node::get();
if (!node) {
return Status::Failure;
}
VerifyOrReturnError(node, Status::Failure);
endpoint_t *endpoint = endpoint::get(node, endpoint_id);
cluster_t *cluster = cluster::get(endpoint, cluster_id);
attribute_t *attribute = attribute::get(cluster, attribute_id);
@@ -2173,9 +2133,7 @@ Status emberAfExternalAttributeWriteCallback(EndpointId endpoint_id, ClusterId c
}
/* Update val */
if (val.type == ESP_MATTER_VAL_TYPE_INVALID) {
return Status::Failure;
}
VerifyOrReturnValue(val.type != ESP_MATTER_VAL_TYPE_INVALID, Status::Failure);
attribute::set_val(attribute, &val);
return Status::Success;
}