examples: simplified attribute retrieval api

This commit is contained in:
mahesh
2024-08-12 12:57:54 +05:30
parent b59fd79370
commit 699d8d0f78
6 changed files with 26 additions and 79 deletions
@@ -33,20 +33,14 @@ extern uint16_t app_endpoint_id;
static void get_attribute(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val)
{
node_t *node = node::get();
endpoint_t *endpoint = endpoint::get(node, endpoint_id);
cluster_t *cluster = cluster::get(endpoint, cluster_id);
attribute_t *attribute = attribute::get(cluster, attribute_id);
attribute_t *attribute = attribute::get(endpoint_id, cluster_id, attribute_id);
attribute::get_val(attribute, val);
}
static esp_err_t set_attribute(uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t val)
{
node_t *node = node::get();
endpoint_t *endpoint = endpoint::get(node, endpoint_id);
cluster_t *cluster = cluster::get(endpoint, cluster_id);
attribute_t *attribute = attribute::get(cluster, attribute_id);
attribute_t *attribute = attribute::get(endpoint_id, cluster_id, attribute_id);
return attribute::set_val(attribute, &val);
}
+6 -19
View File
@@ -68,10 +68,7 @@ static void app_driver_button_toggle_cb(void *arg, void *data)
uint32_t cluster_id = OnOff::Id;
uint32_t attribute_id = OnOff::Attributes::OnOff::Id;
node_t *node = node::get();
endpoint_t *endpoint = endpoint::get(node, endpoint_id);
cluster_t *cluster = cluster::get(endpoint, cluster_id);
attribute_t *attribute = attribute::get(cluster, attribute_id);
attribute_t *attribute = attribute::get(endpoint_id, cluster_id, attribute_id);
esp_matter_attr_val_t val = esp_matter_invalid(NULL);
attribute::get_val(attribute, &val);
@@ -86,9 +83,6 @@ esp_err_t app_driver_attribute_update(app_driver_handle_t driver_handle, uint16_
char vcard_data[MAX_VCARD_ATTR][MAX_ATTR_SIZE];
memset(vcard_data, '\0', sizeof(MAX_VCARD_ATTR * MAX_ATTR_SIZE));
esp_matter_attr_val_t _val = esp_matter_invalid(NULL);
node_t *node = node::get();
endpoint_t *endpoint = endpoint::get(node, 0x0);
cluster_t *cluster = cluster::get(endpoint, BADGE_CLUSTER_ID);
attribute_t *attribute = NULL;
uint32_t _attribute_id = NAME_ATTRIBUTE_ID;
@@ -100,7 +94,7 @@ esp_err_t app_driver_attribute_update(app_driver_handle_t driver_handle, uint16_
_attribute_id++;
continue;
}
attribute = attribute::get(cluster, _attribute_id);
attribute = attribute::get(0x0, cluster_id, _attribute_id);
attribute::get_val(attribute, &_val);
memcpy(vcard_data[i], _val.val.a.b, _val.val.a.s);
vcard_data[i][_val.val.a.s] = '\0';
@@ -133,15 +127,10 @@ esp_err_t app_driver_light_set_defaults(uint16_t endpoint_id)
esp_err_t err = ESP_OK;
void *priv_data = endpoint::get_priv_data(endpoint_id);
led_indicator_handle_t handle = (led_indicator_handle_t)priv_data;
node_t *node = node::get();
endpoint_t *endpoint = endpoint::get(node, endpoint_id);
cluster_t *cluster = NULL;
attribute_t *attribute = NULL;
esp_matter_attr_val_t val = esp_matter_invalid(NULL);
endpoint = endpoint::get(node, 0x0);
cluster = cluster::get(endpoint, BADGE_CLUSTER_ID);
attribute = attribute::get(cluster, NAME_ATTRIBUTE_ID);
attribute = attribute::get(0x0, BADGE_CLUSTER_ID, NAME_ATTRIBUTE_ID);
attribute::get_val(attribute, &val);
if (val.val.a.b[NAME]) {
char vcard_data[MAX_VCARD_ATTR][MAX_ATTR_SIZE];
@@ -150,7 +139,7 @@ esp_err_t app_driver_light_set_defaults(uint16_t endpoint_id)
uint32_t attribute_id = NAME_ATTRIBUTE_ID;
do {
esp_matter_attr_val_t _val = esp_matter_invalid(NULL);
attribute = attribute::get(cluster, attribute_id);
attribute = attribute::get(0x0, BADGE_CLUSTER_ID, attribute_id);
attribute::get_val(attribute, &_val);
memcpy(vcard_data[i], _val.val.a.b, _val.val.a.s);
vcard_data[i][_val.val.a.s] = '\0';
@@ -163,8 +152,7 @@ esp_err_t app_driver_light_set_defaults(uint16_t endpoint_id)
}
/* If nodelabel value is set then display the nodelabel_input */
cluster = cluster::get(endpoint, BasicInformation::Id);
attribute = attribute::get(cluster, BasicInformation::Attributes::NodeLabel::Id);
attribute = attribute::get(0x0, BasicInformation::Id, BasicInformation::Attributes::NodeLabel::Id);
attribute::get_val(attribute, &val);
if (val.val.a.s && !badge_cluster_input_exists) {
set_badge_name(&val);
@@ -173,8 +161,7 @@ esp_err_t app_driver_light_set_defaults(uint16_t endpoint_id)
/* Setting power */
if (!nodelabel_input) {
cluster = cluster::get(endpoint, OnOff::Id);
attribute = attribute::get(cluster, OnOff::Attributes::OnOff::Id);
attribute = attribute::get(0x0, OnOff::Id, OnOff::Attributes::OnOff::Id);
attribute::get_val(attribute, &val);
if (chip::Server::GetInstance().GetFabricTable().FabricCount())
err |= app_driver_light_set_power(handle, &val);
@@ -266,10 +266,7 @@ static void app_driver_button_toggle_cb(void *arg, void *data)
uint32_t cluster_id = OnOff::Id;
uint32_t attribute_id = OnOff::Attributes::OnOff::Id;
node_t *node = node::get();
endpoint_t *endpoint = endpoint::get(node, endpoint_id);
cluster_t *cluster = cluster::get(endpoint, cluster_id);
attribute_t *attribute = attribute::get(cluster, attribute_id);
attribute_t *attribute = attribute::get(endpoint_id, cluster_id, attribute_id);
esp_matter_attr_val_t val = esp_matter_invalid(NULL);
attribute::get_val(attribute, &val);
@@ -309,34 +306,28 @@ esp_err_t app_driver_light_set_defaults(uint16_t endpoint_id)
esp_err_t err = ESP_OK;
void *priv_data = endpoint::get_priv_data(endpoint_id);
led_driver_handle_t handle = (led_driver_handle_t)priv_data;
node_t *node = node::get();
endpoint_t *endpoint = endpoint::get(node, endpoint_id);
cluster_t *cluster = NULL;
attribute_t *attribute = NULL;
esp_matter_attr_val_t val = esp_matter_invalid(NULL);
/* Setting brightness */
cluster = cluster::get(endpoint, LevelControl::Id);
attribute = attribute::get(cluster, LevelControl::Attributes::CurrentLevel::Id);
attribute_t *attribute = attribute::get(endpoint_id, LevelControl::Id, LevelControl::Attributes::CurrentLevel::Id);
attribute::get_val(attribute, &val);
err |= app_driver_light_set_brightness(handle, &val);
/* Setting color */
cluster = cluster::get(endpoint, ColorControl::Id);
attribute = attribute::get(cluster, ColorControl::Attributes::ColorMode::Id);
attribute = attribute::get(endpoint_id, ColorControl::Id, ColorControl::Attributes::ColorMode::Id);
attribute::get_val(attribute, &val);
if (val.val.u8 == (uint8_t)ColorControl::ColorMode::kCurrentHueAndCurrentSaturation) {
/* Setting hue */
attribute = attribute::get(cluster, ColorControl::Attributes::CurrentHue::Id);
attribute = attribute::get(endpoint_id, ColorControl::Id, ColorControl::Attributes::CurrentHue::Id);
attribute::get_val(attribute, &val);
err |= app_driver_light_set_hue(handle, &val);
/* Setting saturation */
attribute = attribute::get(cluster, ColorControl::Attributes::CurrentSaturation::Id);
attribute = attribute::get(endpoint_id, ColorControl::Id, ColorControl::Attributes::CurrentSaturation::Id);
attribute::get_val(attribute, &val);
err |= app_driver_light_set_saturation(handle, &val);
} else if (val.val.u8 == (uint8_t)ColorControl::ColorMode::kColorTemperature) {
/* Setting temperature */
attribute = attribute::get(cluster, ColorControl::Attributes::ColorTemperatureMireds::Id);
attribute = attribute::get(endpoint_id, ColorControl::Id, ColorControl::Attributes::ColorTemperatureMireds::Id);
attribute::get_val(attribute, &val);
err |= app_driver_light_set_temperature(handle, &val);
} else {
@@ -344,8 +335,7 @@ esp_err_t app_driver_light_set_defaults(uint16_t endpoint_id)
}
/* Setting power */
cluster = cluster::get(endpoint, OnOff::Id);
attribute = attribute::get(cluster, OnOff::Attributes::OnOff::Id);
attribute = attribute::get(endpoint_id, OnOff::Id, OnOff::Attributes::OnOff::Id);
attribute::get_val(attribute, &val);
err |= app_driver_light_set_power(handle, &val);
@@ -59,10 +59,7 @@ static void espnow_ctrl_onoff(espnow_addr_t src_addr, bool status)
uint32_t cluster_id = OnOff::Id;
uint32_t attribute_id = OnOff::Attributes::OnOff::Id;
node_t *node = node::get();
endpoint_t *endpoint = endpoint::get(node, endpoint_id);
cluster_t *cluster = cluster::get(endpoint, cluster_id);
attribute_t *attribute = attribute::get(cluster, attribute_id);
attribute_t *attribute = attribute::get(endpoint_id, cluster_id, attribute_id);
esp_matter_attr_val_t val = esp_matter_invalid(NULL);
attribute::get_val(attribute, &val);
@@ -104,10 +101,7 @@ static void espnow_event_handler(void* handler_args, esp_event_base_t base, int3
uint32_t cluster_id = OnOff::Id;
uint32_t attribute_id = OnOff::Attributes::OnOff::Id;
node_t *node = node::get();
endpoint_t *endpoint = endpoint::get(node, endpoint_id);
cluster_t *cluster = cluster::get(endpoint, cluster_id);
attribute_t *attribute = attribute::get(cluster, attribute_id);
attribute_t *attribute = attribute::get(endpoint_id, cluster_id, attribute_id);
esp_matter_attr_val_t val = esp_matter_invalid(NULL);
+7 -17
View File
@@ -95,10 +95,7 @@ static void app_driver_button_toggle_cb(void *arg, void *data)
uint32_t cluster_id = OnOff::Id;
uint32_t attribute_id = OnOff::Attributes::OnOff::Id;
node_t *node = node::get();
endpoint_t *endpoint = endpoint::get(node, endpoint_id);
cluster_t *cluster = cluster::get(endpoint, cluster_id);
attribute_t *attribute = attribute::get(cluster, attribute_id);
attribute_t *attribute = attribute::get(endpoint_id, cluster_id, attribute_id);
esp_matter_attr_val_t val = esp_matter_invalid(NULL);
attribute::get_val(attribute, &val);
@@ -138,34 +135,28 @@ esp_err_t app_driver_light_set_defaults(uint16_t endpoint_id)
esp_err_t err = ESP_OK;
void *priv_data = endpoint::get_priv_data(endpoint_id);
led_indicator_handle_t handle = (led_indicator_handle_t)priv_data;
node_t *node = node::get();
endpoint_t *endpoint = endpoint::get(node, endpoint_id);
cluster_t *cluster = NULL;
attribute_t *attribute = NULL;
esp_matter_attr_val_t val = esp_matter_invalid(NULL);
/* Setting brightness */
cluster = cluster::get(endpoint, LevelControl::Id);
attribute = attribute::get(cluster, LevelControl::Attributes::CurrentLevel::Id);
attribute_t *attribute = attribute::get(endpoint_id, LevelControl::Id, LevelControl::Attributes::CurrentLevel::Id);
attribute::get_val(attribute, &val);
err |= app_driver_light_set_brightness(handle, &val);
/* Setting color */
cluster = cluster::get(endpoint, ColorControl::Id);
attribute = attribute::get(cluster, ColorControl::Attributes::ColorMode::Id);
attribute = attribute::get(endpoint_id, ColorControl::Id, ColorControl::Attributes::ColorMode::Id);
attribute::get_val(attribute, &val);
if (val.val.u8 == (uint8_t)ColorControl::ColorMode::kCurrentHueAndCurrentSaturation) {
/* Setting hue */
attribute = attribute::get(cluster, ColorControl::Attributes::CurrentHue::Id);
attribute = attribute::get(endpoint_id, ColorControl::Id, ColorControl::Attributes::CurrentHue::Id);
attribute::get_val(attribute, &val);
err |= app_driver_light_set_hue(handle, &val);
/* Setting saturation */
attribute = attribute::get(cluster, ColorControl::Attributes::CurrentSaturation::Id);
attribute = attribute::get(endpoint_id, ColorControl::Id, ColorControl::Attributes::CurrentSaturation::Id);
attribute::get_val(attribute, &val);
err |= app_driver_light_set_saturation(handle, &val);
} else if (val.val.u8 == (uint8_t)ColorControl::ColorMode::kColorTemperature) {
/* Setting temperature */
attribute = attribute::get(cluster, ColorControl::Attributes::ColorTemperatureMireds::Id);
attribute = attribute::get(endpoint_id, ColorControl::Id, ColorControl::Attributes::ColorTemperatureMireds::Id);
attribute::get_val(attribute, &val);
err |= app_driver_light_set_temperature(handle, &val);
} else {
@@ -173,8 +164,7 @@ esp_err_t app_driver_light_set_defaults(uint16_t endpoint_id)
}
/* Setting power */
cluster = cluster::get(endpoint, OnOff::Id);
attribute = attribute::get(cluster, OnOff::Attributes::OnOff::Id);
attribute = attribute::get(endpoint_id, OnOff::Id, OnOff::Attributes::OnOff::Id);
attribute::get_val(attribute, &val);
err |= app_driver_light_set_power(handle, &val);
@@ -35,10 +35,7 @@ static void app_driver_button_toggle_cb(void *arg, void *data)
uint32_t cluster_id = OnOff::Id;
uint32_t attribute_id = OnOff::Attributes::OnOff::Id;
node_t *node = node::get();
endpoint_t *endpoint = endpoint::get(node, endpoint_id);
cluster_t *cluster = cluster::get(endpoint, cluster_id);
attribute_t *attribute = attribute::get(cluster, attribute_id);
attribute_t *attribute = attribute::get(endpoint_id, cluster_id, attribute_id);
esp_matter_attr_val_t val = esp_matter_invalid(NULL);
attribute::get_val(attribute, &val);
@@ -66,15 +63,10 @@ esp_err_t app_driver_room_air_conditioner_set_defaults(uint16_t endpoint_id)
esp_err_t err = ESP_OK;
void *priv_data = endpoint::get_priv_data(endpoint_id);
led_driver_handle_t handle = (led_driver_handle_t)priv_data;
node_t *node = node::get();
endpoint_t *endpoint = endpoint::get(node, endpoint_id);
cluster_t *cluster = NULL;
attribute_t *attribute = NULL;
esp_matter_attr_val_t val = esp_matter_invalid(NULL);
/* Setting power */
cluster = cluster::get(endpoint, OnOff::Id);
attribute = attribute::get(cluster, OnOff::Attributes::OnOff::Id);
attribute_t *attribute = attribute::get(endpoint_id, OnOff::Id, OnOff::Attributes::OnOff::Id);
attribute::get_val(attribute, &val);
err |= app_driver_room_air_conditioner_set_power(handle, &val);