mirror of
https://github.com/espressif/esp-matter.git
synced 2026-04-27 19:13:13 +00:00
Merge branch 'bugfix/attribute_defaults' into 'main'
app_driver: Setting the default attribute values for the driver See merge request app-frameworks/esp-matter!60
This commit is contained in:
@@ -582,6 +582,17 @@ esp_err_t esp_matter_attribute_callback_set(esp_matter_attribute_callback_t call
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_matter_attribute_get_val_raw(int endpoint_id, int cluster_id, int attribute_id, uint8_t *value,
|
||||
uint16_t attribute_size)
|
||||
{
|
||||
EmberAfStatus status = emberAfReadServerAttribute(endpoint_id, cluster_id, attribute_id, value, attribute_size);
|
||||
if (status != EMBER_ZCL_STATUS_SUCCESS) {
|
||||
ESP_LOGE(TAG, "Error getting raw value from matter");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_matter_attribute_update(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t val)
|
||||
{
|
||||
EmberAfAttributeType attribute_type = 0;
|
||||
|
||||
@@ -174,7 +174,8 @@ esp_err_t esp_matter_endpoint_enable(esp_matter_endpoint_t *endpoint)
|
||||
static esp_err_t esp_matter_endpoint_enable_all()
|
||||
{
|
||||
if (!node) {
|
||||
return ESP_FAIL;
|
||||
/* Not returning error, since the node will not be initialized for application using the data model from zap */
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
_esp_matter_endpoint_t *endpoint = node->endpoint_list;
|
||||
@@ -246,7 +247,6 @@ esp_err_t esp_matter_start(esp_matter_event_callback_t callback)
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Error initializing matter");
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
@@ -78,6 +78,8 @@ int esp_matter_attribute_get_id(esp_matter_attribute_t *attribute);
|
||||
/** Attribute val APIs */
|
||||
esp_err_t esp_matter_attribute_set_val(esp_matter_attribute_t *attribute, esp_matter_attr_val_t val);
|
||||
esp_matter_attr_val_t esp_matter_attribute_get_val(esp_matter_attribute_t *attribute);
|
||||
esp_err_t esp_matter_attribute_get_val_raw(int endpoint_id, int cluster_id, int attribute_id, uint8_t *value,
|
||||
uint16_t attribute_size);
|
||||
|
||||
/** Command APIs */
|
||||
esp_matter_command_t *esp_matter_command_create(esp_matter_cluster_t *cluster, int command_id, uint8_t flags,
|
||||
|
||||
@@ -37,7 +37,7 @@ static esp_err_t app_driver_console_handler(int argc, char **argv)
|
||||
int attribute_id = strtol((const char *)&argv[3][2], NULL, 16);
|
||||
int value = atoi(argv[4]);
|
||||
|
||||
esp_matter_attr_val_t val = esp_matter_int(value);
|
||||
esp_matter_attr_val_t val = esp_matter_uint8(value);
|
||||
|
||||
/* Change val if bool */
|
||||
if (cluster_id == ZCL_ON_OFF_CLUSTER_ID && attribute_id == ZCL_ON_OFF_ATTRIBUTE_ID) {
|
||||
@@ -84,19 +84,19 @@ static esp_err_t app_driver_light_set_power(esp_matter_attr_val_t val)
|
||||
|
||||
static esp_err_t app_driver_light_set_brightness(esp_matter_attr_val_t val)
|
||||
{
|
||||
int value = REMAP_TO_RANGE(val.val.i, MATTER_BRIGHTNESS, STANDARD_BRIGHTNESS);
|
||||
int value = REMAP_TO_RANGE(val.val.u8, MATTER_BRIGHTNESS, STANDARD_BRIGHTNESS);
|
||||
return light_driver_set_brightness(value);
|
||||
}
|
||||
|
||||
static esp_err_t app_driver_light_set_hue(esp_matter_attr_val_t val)
|
||||
{
|
||||
int value = REMAP_TO_RANGE(val.val.i, MATTER_HUE, STANDARD_HUE);
|
||||
int value = REMAP_TO_RANGE(val.val.u8, MATTER_HUE, STANDARD_HUE);
|
||||
return light_driver_set_hue(value);
|
||||
}
|
||||
|
||||
static esp_err_t app_driver_light_set_saturation(esp_matter_attr_val_t val)
|
||||
{
|
||||
int value = REMAP_TO_RANGE(val.val.i, MATTER_SATURATION, STANDARD_SATURATION);
|
||||
int value = REMAP_TO_RANGE(val.val.u8, MATTER_SATURATION, STANDARD_SATURATION);
|
||||
return light_driver_set_saturation(value);
|
||||
}
|
||||
|
||||
@@ -123,9 +123,35 @@ esp_err_t app_driver_attribute_update(int endpoint_id, int cluster_id, int attri
|
||||
return err;
|
||||
}
|
||||
|
||||
static esp_err_t app_driver_attribute_set_defaults()
|
||||
{
|
||||
/* Get the default value (current value) from esp_matter and update the app_driver */
|
||||
esp_err_t err = ESP_OK;
|
||||
esp_matter_node_t *node = esp_matter_node_get();
|
||||
esp_matter_endpoint_t *endpoint = esp_matter_endpoint_get_first(node);
|
||||
while (endpoint) {
|
||||
int endpoint_id = esp_matter_endpoint_get_id(endpoint);
|
||||
esp_matter_cluster_t *cluster = esp_matter_cluster_get_first(endpoint);
|
||||
while (cluster) {
|
||||
int cluster_id = esp_matter_cluster_get_id(cluster);
|
||||
esp_matter_attribute_t *attribute = esp_matter_attribute_get_first(cluster);
|
||||
while (attribute) {
|
||||
int attribute_id = esp_matter_attribute_get_id(attribute);
|
||||
esp_matter_attr_val_t val = esp_matter_attribute_get_val(attribute);
|
||||
err |= app_driver_attribute_update(endpoint_id, cluster_id, attribute_id, val);
|
||||
attribute = esp_matter_attribute_get_next(attribute);
|
||||
}
|
||||
cluster = esp_matter_cluster_get_next(cluster);
|
||||
}
|
||||
endpoint = esp_matter_endpoint_get_next(endpoint);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t app_driver_init()
|
||||
{
|
||||
device_init();
|
||||
app_driver_attribute_set_defaults();
|
||||
app_driver_register_commands();
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ static esp_err_t app_driver_console_handler(int argc, char **argv)
|
||||
int attribute_id = strtol((const char *)&argv[3][2], NULL, 16);
|
||||
int value = atoi(argv[4]);
|
||||
|
||||
esp_matter_attr_val_t val = esp_matter_int(value);
|
||||
esp_matter_attr_val_t val = esp_matter_uint8(value);
|
||||
|
||||
/* Change val if bool */
|
||||
if (cluster_id == ZCL_ON_OFF_CLUSTER_ID && attribute_id == ZCL_ON_OFF_ATTRIBUTE_ID) {
|
||||
@@ -84,19 +84,19 @@ static esp_err_t app_driver_light_set_power(esp_matter_attr_val_t val)
|
||||
|
||||
static esp_err_t app_driver_light_set_brightness(esp_matter_attr_val_t val)
|
||||
{
|
||||
int value = REMAP_TO_RANGE(val.val.i, MATTER_BRIGHTNESS, STANDARD_BRIGHTNESS);
|
||||
int value = REMAP_TO_RANGE(val.val.u8, MATTER_BRIGHTNESS, STANDARD_BRIGHTNESS);
|
||||
return light_driver_set_brightness(value);
|
||||
}
|
||||
|
||||
static esp_err_t app_driver_light_set_hue(esp_matter_attr_val_t val)
|
||||
{
|
||||
int value = REMAP_TO_RANGE(val.val.i, MATTER_HUE, STANDARD_HUE);
|
||||
int value = REMAP_TO_RANGE(val.val.u8, MATTER_HUE, STANDARD_HUE);
|
||||
return light_driver_set_hue(value);
|
||||
}
|
||||
|
||||
static esp_err_t app_driver_light_set_saturation(esp_matter_attr_val_t val)
|
||||
{
|
||||
int value = REMAP_TO_RANGE(val.val.i, MATTER_SATURATION, STANDARD_SATURATION);
|
||||
int value = REMAP_TO_RANGE(val.val.u8, MATTER_SATURATION, STANDARD_SATURATION);
|
||||
return light_driver_set_saturation(value);
|
||||
}
|
||||
|
||||
@@ -123,9 +123,35 @@ esp_err_t app_driver_attribute_update(int endpoint_id, int cluster_id, int attri
|
||||
return err;
|
||||
}
|
||||
|
||||
static esp_err_t app_driver_attribute_set_defaults()
|
||||
{
|
||||
/* Get the default value (current value) from esp_matter and update the app_driver */
|
||||
esp_err_t err = ESP_OK;
|
||||
esp_matter_node_t *node = esp_matter_node_get();
|
||||
esp_matter_endpoint_t *endpoint = esp_matter_endpoint_get_first(node);
|
||||
while (endpoint) {
|
||||
int endpoint_id = esp_matter_endpoint_get_id(endpoint);
|
||||
esp_matter_cluster_t *cluster = esp_matter_cluster_get_first(endpoint);
|
||||
while (cluster) {
|
||||
int cluster_id = esp_matter_cluster_get_id(cluster);
|
||||
esp_matter_attribute_t *attribute = esp_matter_attribute_get_first(cluster);
|
||||
while (attribute) {
|
||||
int attribute_id = esp_matter_attribute_get_id(attribute);
|
||||
esp_matter_attr_val_t val = esp_matter_attribute_get_val(attribute);
|
||||
err |= app_driver_attribute_update(endpoint_id, cluster_id, attribute_id, val);
|
||||
attribute = esp_matter_attribute_get_next(attribute);
|
||||
}
|
||||
cluster = esp_matter_cluster_get_next(cluster);
|
||||
}
|
||||
endpoint = esp_matter_endpoint_get_next(endpoint);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t app_driver_init()
|
||||
{
|
||||
device_init();
|
||||
app_driver_attribute_set_defaults();
|
||||
app_driver_register_commands();
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ static esp_err_t app_driver_console_handler(int argc, char **argv)
|
||||
int attribute_id = strtol((const char *)&argv[3][2], NULL, 16);
|
||||
int value = atoi(argv[4]);
|
||||
|
||||
esp_matter_attr_val_t val = esp_matter_int(value);
|
||||
esp_matter_attr_val_t val = esp_matter_uint8(value);
|
||||
|
||||
/* Change val if bool */
|
||||
if (cluster_id == ZCL_ON_OFF_CLUSTER_ID && attribute_id == ZCL_ON_OFF_ATTRIBUTE_ID) {
|
||||
@@ -77,7 +77,7 @@ static esp_err_t app_driver_console_handler(int argc, char **argv)
|
||||
int attribute_id = strtol((const char *)&argv[3][2], NULL, 16);
|
||||
int value = app_driver_light_get_attribute(endpoint_id, cluster_id, attribute_id);
|
||||
|
||||
esp_matter_attr_val_t val = esp_matter_int(value);
|
||||
esp_matter_attr_val_t val = esp_matter_uint8(value);
|
||||
|
||||
/* Change val if bool */
|
||||
if (cluster_id == ZCL_ON_OFF_CLUSTER_ID && attribute_id == ZCL_ON_OFF_ATTRIBUTE_ID) {
|
||||
@@ -113,19 +113,19 @@ static esp_err_t app_driver_light_set_power(esp_matter_attr_val_t val)
|
||||
|
||||
static esp_err_t app_driver_light_set_brightness(esp_matter_attr_val_t val)
|
||||
{
|
||||
int value = REMAP_TO_RANGE(val.val.i, MATTER_BRIGHTNESS, STANDARD_BRIGHTNESS);
|
||||
int value = REMAP_TO_RANGE(val.val.u8, MATTER_BRIGHTNESS, STANDARD_BRIGHTNESS);
|
||||
return light_driver_set_brightness(value);
|
||||
}
|
||||
|
||||
static esp_err_t app_driver_light_set_hue(esp_matter_attr_val_t val)
|
||||
{
|
||||
int value = REMAP_TO_RANGE(val.val.i, MATTER_HUE, STANDARD_HUE);
|
||||
int value = REMAP_TO_RANGE(val.val.u8, MATTER_HUE, STANDARD_HUE);
|
||||
return light_driver_set_hue(value);
|
||||
}
|
||||
|
||||
static esp_err_t app_driver_light_set_saturation(esp_matter_attr_val_t val)
|
||||
{
|
||||
int value = REMAP_TO_RANGE(val.val.i, MATTER_SATURATION, STANDARD_SATURATION);
|
||||
int value = REMAP_TO_RANGE(val.val.u8, MATTER_SATURATION, STANDARD_SATURATION);
|
||||
return light_driver_set_saturation(value);
|
||||
}
|
||||
|
||||
@@ -152,6 +152,49 @@ esp_err_t app_driver_attribute_update(int endpoint_id, int cluster_id, int attri
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t app_driver_attribute_set_defaults()
|
||||
{
|
||||
/* When using static endpoints, i.e. using the data model from zap-generated, this needs to be done
|
||||
after esp_matter_start() */
|
||||
/* Get the default value (current value) from matter submodule and update the app_driver */
|
||||
esp_err_t err = ESP_OK;
|
||||
uint8_t value;
|
||||
int endpoint_id = 0;
|
||||
int cluster_id = 0;
|
||||
int attribute_id = 0;
|
||||
esp_matter_attr_val_t val = esp_matter_invalid(NULL);
|
||||
|
||||
endpoint_id = ESP_MATTER_COLOR_DIMMABLE_LIGHT_ENDPOINT_ID;
|
||||
cluster_id = ZCL_ON_OFF_CLUSTER_ID;
|
||||
attribute_id = ZCL_ON_OFF_ATTRIBUTE_ID;
|
||||
esp_matter_attribute_get_val_raw(endpoint_id, cluster_id, attribute_id, &value, sizeof(uint8_t));
|
||||
val = esp_matter_bool(value);
|
||||
err |= app_driver_attribute_update(endpoint_id, cluster_id, attribute_id, val);
|
||||
|
||||
endpoint_id = ESP_MATTER_COLOR_DIMMABLE_LIGHT_ENDPOINT_ID;
|
||||
cluster_id = ZCL_LEVEL_CONTROL_CLUSTER_ID;
|
||||
attribute_id = ZCL_CURRENT_LEVEL_ATTRIBUTE_ID;
|
||||
esp_matter_attribute_get_val_raw(endpoint_id, cluster_id, attribute_id, &value, sizeof(uint8_t));
|
||||
val = esp_matter_uint8(value);
|
||||
err |= app_driver_attribute_update(endpoint_id, cluster_id, attribute_id, val);
|
||||
|
||||
endpoint_id = ESP_MATTER_COLOR_DIMMABLE_LIGHT_ENDPOINT_ID;
|
||||
cluster_id = ZCL_COLOR_CONTROL_CLUSTER_ID;
|
||||
attribute_id = ZCL_COLOR_CONTROL_CURRENT_HUE_ATTRIBUTE_ID;
|
||||
esp_matter_attribute_get_val_raw(endpoint_id, cluster_id, attribute_id, &value, sizeof(uint8_t));
|
||||
val = esp_matter_uint8(value);
|
||||
err |= app_driver_attribute_update(endpoint_id, cluster_id, attribute_id, val);
|
||||
|
||||
endpoint_id = ESP_MATTER_COLOR_DIMMABLE_LIGHT_ENDPOINT_ID;
|
||||
cluster_id = ZCL_COLOR_CONTROL_CLUSTER_ID;
|
||||
attribute_id = ZCL_COLOR_CONTROL_CURRENT_SATURATION_ATTRIBUTE_ID;
|
||||
esp_matter_attribute_get_val_raw(endpoint_id, cluster_id, attribute_id, &value, sizeof(uint8_t));
|
||||
val = esp_matter_uint8(value);
|
||||
err |= app_driver_attribute_update(endpoint_id, cluster_id, attribute_id, val);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t app_driver_init()
|
||||
{
|
||||
device_init();
|
||||
|
||||
@@ -26,6 +26,8 @@ esp_err_t app_driver_init(void);
|
||||
|
||||
esp_err_t app_driver_attribute_update(int endpoint_id, int cluster_id, int attribute_id, esp_matter_attr_val_t val);
|
||||
|
||||
esp_err_t app_driver_attribute_set_defaults();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -64,6 +64,8 @@ extern "C" void app_main()
|
||||
}
|
||||
app_qrcode_print();
|
||||
|
||||
app_driver_attribute_set_defaults();
|
||||
|
||||
#if CONFIG_ENABLE_CHIP_SHELL
|
||||
esp_matter_console_diagnostics_register_commands();
|
||||
esp_matter_console_init();
|
||||
|
||||
Reference in New Issue
Block a user