Skip to content

Commit

Permalink
Merge branch 'fan-ctrl' into 'main'
Browse files Browse the repository at this point in the history
Add bounds to fan control cluster attributes

See merge request app-frameworks/esp-matter!541
  • Loading branch information
dhrishi committed Nov 8, 2023
2 parents e3907d0 + cbcbfa8 commit d162b13
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
33 changes: 27 additions & 6 deletions components/esp_matter/esp_matter_attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t> value)
attribute_t *create_percent_setting(cluster_t *cluster, nullable<uint8_t> 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)
Expand Down
6 changes: 3 additions & 3 deletions components/esp_matter/esp_matter_attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,9 @@ attribute_t *create_primary_n_intensity(cluster_t * cluster, nullable<uint8_t> 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<uint8_t> 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<uint8_t> 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<uint8_t> value, uint8_t min, uint8_t max);
attribute_t *create_speed_current(cluster_t *cluster, uint8_t value, uint8_t min, uint8_t max);
Expand Down
6 changes: 3 additions & 3 deletions components/esp_matter/esp_matter_cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Expand Down

0 comments on commit d162b13

Please sign in to comment.