From cbcbfa8af0b0d4e059816f5ef821f5f4491c0282 Mon Sep 17 00:00:00 2001 From: PSONALl Date: Tue, 7 Nov 2023 18:48:19 +0530 Subject: [PATCH] Add bounds to fan control cluster attributes --- .../esp_matter/esp_matter_attribute.cpp | 33 +++++++++++++++---- components/esp_matter/esp_matter_attribute.h | 6 ++-- components/esp_matter/esp_matter_cluster.cpp | 6 ++-- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/components/esp_matter/esp_matter_attribute.cpp b/components/esp_matter/esp_matter_attribute.cpp index abec359b2..32db1d12a 100644 --- a/components/esp_matter/esp_matter_attribute.cpp +++ b/components/esp_matter/esp_matter_attribute.cpp @@ -1494,23 +1494,44 @@ attribute_t *create_fan_mode(cluster_t *cluster, uint8_t value, uint8_t min, uin return attribute; } -attribute_t *create_fan_mode_sequence(cluster_t *cluster, const uint8_t value) +attribute_t *create_fan_mode_sequence(cluster_t *cluster, const uint8_t value, uint8_t min, uint8_t max) { - return esp_matter::attribute::create(cluster, FanControl::Attributes::FanModeSequence::Id, + attribute_t *attribute = + esp_matter::attribute::create(cluster, FanControl::Attributes::FanModeSequence::Id, ATTRIBUTE_FLAG_NONE, esp_matter_enum8(value)); + if (!attribute) { + ESP_LOGE(TAG, "Could not create attribute"); + return NULL; + } + esp_matter::attribute::add_bounds(attribute, esp_matter_enum8(min), esp_matter_enum8(max)); + return attribute; } -attribute_t *create_percent_setting(cluster_t *cluster, nullable value) +attribute_t *create_percent_setting(cluster_t *cluster, nullable value, uint8_t min, uint8_t max) { - return esp_matter::attribute::create(cluster, FanControl::Attributes::PercentSetting::Id, + attribute_t *attribute = + esp_matter::attribute::create(cluster, FanControl::Attributes::PercentSetting::Id, ATTRIBUTE_FLAG_NULLABLE | ATTRIBUTE_FLAG_WRITABLE, esp_matter_nullable_uint8(value)); + if (!attribute) { + ESP_LOGE(TAG, "Could not create attribute"); + return NULL; + } + esp_matter::attribute::add_bounds(attribute, esp_matter_uint8(min), esp_matter_uint8(max)); + return attribute; } -attribute_t *create_percent_current(cluster_t *cluster, uint8_t value) +attribute_t *create_percent_current(cluster_t *cluster, uint8_t value, uint8_t min, uint8_t max) { - return esp_matter::attribute::create(cluster, FanControl::Attributes::PercentCurrent::Id, ATTRIBUTE_FLAG_NONE, + attribute_t *attribute = + esp_matter::attribute::create(cluster, FanControl::Attributes::PercentCurrent::Id, ATTRIBUTE_FLAG_NONE, esp_matter_uint8(value)); + if (!attribute) { + ESP_LOGE(TAG, "Could not create attribute"); + return NULL; + } + esp_matter::attribute::add_bounds(attribute, esp_matter_uint8(min), esp_matter_uint8(max)); + return attribute; } attribute_t *create_speed_max(cluster_t *cluster, uint8_t value, uint8_t min, uint8_t max) diff --git a/components/esp_matter/esp_matter_attribute.h b/components/esp_matter/esp_matter_attribute.h index 66fc442a8..727457bdc 100644 --- a/components/esp_matter/esp_matter_attribute.h +++ b/components/esp_matter/esp_matter_attribute.h @@ -356,9 +356,9 @@ attribute_t *create_primary_n_intensity(cluster_t * cluster, nullable v namespace fan_control { namespace attribute { attribute_t *create_fan_mode(cluster_t *cluster, uint8_t value, uint8_t min, uint8_t max); -attribute_t *create_fan_mode_sequence(cluster_t *cluster, const uint8_t value); -attribute_t *create_percent_setting(cluster_t *cluster, nullable value); -attribute_t *create_percent_current(cluster_t *cluster, uint8_t value); +attribute_t *create_fan_mode_sequence(cluster_t *cluster, const uint8_t value, uint8_t min, uint8_t max); +attribute_t *create_percent_setting(cluster_t *cluster, nullable value, uint8_t min, uint8_t max); +attribute_t *create_percent_current(cluster_t *cluster, uint8_t value, uint8_t min, uint8_t max); attribute_t *create_speed_max(cluster_t *cluster, uint8_t value, uint8_t min, uint8_t max); attribute_t *create_speed_setting(cluster_t *cluster, nullable value, uint8_t min, uint8_t max); attribute_t *create_speed_current(cluster_t *cluster, uint8_t value, uint8_t min, uint8_t max); diff --git a/components/esp_matter/esp_matter_cluster.cpp b/components/esp_matter/esp_matter_cluster.cpp index 025e8d14f..ab8dd71a5 100644 --- a/components/esp_matter/esp_matter_cluster.cpp +++ b/components/esp_matter/esp_matter_cluster.cpp @@ -1376,9 +1376,9 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) if (config) { global::attribute::create_cluster_revision(cluster, config->cluster_revision); attribute::create_fan_mode(cluster, config->fan_mode, 0, 6); - attribute::create_fan_mode_sequence(cluster, config->fan_mode_sequence); - attribute::create_percent_setting(cluster, config->percent_setting); - attribute::create_percent_current(cluster, config->percent_current); + attribute::create_fan_mode_sequence(cluster, config->fan_mode_sequence, 0, 5); + attribute::create_percent_setting(cluster, config->percent_setting, 0, 100); + attribute::create_percent_current(cluster, config->percent_current, 0, 100); } else { ESP_LOGE(TAG, "Config is NULL. Cannot add some attributes."); }