@@ -55,20 +55,28 @@ bool ZigbeeEP::setManufacturerAndModel(const char *name, const char *model) {
55
55
56
56
// Get the basic cluster and update the manufacturer and model attributes
57
57
esp_zb_attribute_list_t *basic_cluster = esp_zb_cluster_list_get_cluster (_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_BASIC, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
58
- esp_err_t ret_manufacturer = esp_zb_basic_cluster_add_attr (basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID, (void *)zb_name);
59
- esp_err_t ret_model = esp_zb_basic_cluster_add_attr (basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID, (void *)zb_model);
60
- if (ret_manufacturer != ESP_OK || ret_model != ESP_OK) {
61
- log_e (" Failed to set manufacturer (0x%x) or model (0x%x)" , ret_manufacturer, ret_model);
58
+ esp_err_t ret = esp_zb_basic_cluster_add_attr (basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID, (void *)zb_name);
59
+ if (ret != ESP_OK) {
60
+ log_e (" Failed to set manufacturer: 0x%x: %s" , ret, esp_err_to_name (ret));
61
+ return false ;
62
+ }
63
+ ret = esp_zb_basic_cluster_add_attr (basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID, (void *)zb_model);
64
+ if (ret != ESP_OK) {
65
+ log_e (" Failed to set model: 0x%x: %s" , ret, esp_err_to_name (ret));
66
+ return false ;
62
67
}
63
-
64
68
delete[] zb_name;
65
69
delete[] zb_model;
66
- return ret_manufacturer == ESP_OK && ret_model == ESP_OK ;
70
+ return true ;
67
71
}
68
72
69
- void ZigbeeEP::setPowerSource (zb_power_source_t power_source, uint8_t battery_percentage) {
73
+ bool ZigbeeEP::setPowerSource (zb_power_source_t power_source, uint8_t battery_percentage) {
70
74
esp_zb_attribute_list_t *basic_cluster = esp_zb_cluster_list_get_cluster (_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_BASIC, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
71
- esp_zb_cluster_update_attr (basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_POWER_SOURCE_ID, (void *)&power_source);
75
+ esp_err_t ret = esp_zb_cluster_update_attr (basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_POWER_SOURCE_ID, (void *)&power_source);
76
+ if (ret != ESP_OK) {
77
+ log_e (" Failed to set power source: 0x%x: %s" , ret, esp_err_to_name (ret));
78
+ return false ;
79
+ }
72
80
73
81
if (power_source == ZB_POWER_SOURCE_BATTERY) {
74
82
// Add power config cluster and battery percentage attribute
@@ -77,10 +85,19 @@ void ZigbeeEP::setPowerSource(zb_power_source_t power_source, uint8_t battery_pe
77
85
}
78
86
battery_percentage = battery_percentage * 2 ;
79
87
esp_zb_attribute_list_t *power_config_cluster = esp_zb_zcl_attr_list_create (ESP_ZB_ZCL_CLUSTER_ID_POWER_CONFIG);
80
- esp_zb_power_config_cluster_add_attr (power_config_cluster, ESP_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_PERCENTAGE_REMAINING_ID, (void *)&battery_percentage);
81
- esp_zb_cluster_list_add_power_config_cluster (_cluster_list, power_config_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
88
+ ret = esp_zb_power_config_cluster_add_attr (power_config_cluster, ESP_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_PERCENTAGE_REMAINING_ID, (void *)&battery_percentage);
89
+ if (ret != ESP_OK) {
90
+ log_e (" Failed to add battery percentage attribute: 0x%x: %s" , ret, esp_err_to_name (ret));
91
+ return false ;
92
+ }
93
+ ret = esp_zb_cluster_list_add_power_config_cluster (_cluster_list, power_config_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
94
+ if (ret != ESP_OK) {
95
+ log_e (" Failed to add power config cluster: 0x%x: %s" , ret, esp_err_to_name (ret));
96
+ return false ;
97
+ }
82
98
}
83
99
_power_source = power_source;
100
+ return true ;
84
101
}
85
102
86
103
bool ZigbeeEP::setBatteryPercentage (uint8_t percentage) {
@@ -258,7 +275,7 @@ void ZigbeeEP::zbIdentify(const esp_zb_zcl_set_attr_value_message_t *message) {
258
275
}
259
276
}
260
277
261
- void ZigbeeEP::addTimeCluster (tm time, int32_t gmt_offset) {
278
+ bool ZigbeeEP::addTimeCluster (tm time, int32_t gmt_offset) {
262
279
time_t utc_time = 0 ;
263
280
// Check if time is set
264
281
if (time .tm_year > 0 ) {
@@ -268,14 +285,35 @@ void ZigbeeEP::addTimeCluster(tm time, int32_t gmt_offset) {
268
285
269
286
// Create time cluster server attributes
270
287
esp_zb_attribute_list_t *time_cluster_server = esp_zb_zcl_attr_list_create (ESP_ZB_ZCL_CLUSTER_ID_TIME);
271
- esp_zb_time_cluster_add_attr (time_cluster_server, ESP_ZB_ZCL_ATTR_TIME_TIME_ZONE_ID, (void *)&gmt_offset);
272
- esp_zb_time_cluster_add_attr (time_cluster_server, ESP_ZB_ZCL_ATTR_TIME_TIME_ID, (void *)&utc_time);
273
- esp_zb_time_cluster_add_attr (time_cluster_server, ESP_ZB_ZCL_ATTR_TIME_TIME_STATUS_ID, (void *)&_time_status);
288
+ esp_err_t ret = esp_zb_time_cluster_add_attr (time_cluster_server, ESP_ZB_ZCL_ATTR_TIME_TIME_ZONE_ID, (void *)&gmt_offset);
289
+ if (ret != ESP_OK) {
290
+ log_e (" Failed to add time zone attribute: 0x%x: %s" , ret, esp_err_to_name (ret));
291
+ return false ;
292
+ }
293
+ ret = esp_zb_time_cluster_add_attr (time_cluster_server, ESP_ZB_ZCL_ATTR_TIME_TIME_ID, (void *)&utc_time);
294
+ if (ret != ESP_OK) {
295
+ log_e (" Failed to add time attribute: 0x%x: %s" , ret, esp_err_to_name (ret));
296
+ return false ;
297
+ }
298
+ ret = esp_zb_time_cluster_add_attr (time_cluster_server, ESP_ZB_ZCL_ATTR_TIME_TIME_STATUS_ID, (void *)&_time_status);
299
+ if (ret != ESP_OK) {
300
+ log_e (" Failed to add time status attribute: 0x%x: %s" , ret, esp_err_to_name (ret));
301
+ return false ;
302
+ }
274
303
// Create time cluster client attributes
275
304
esp_zb_attribute_list_t *time_cluster_client = esp_zb_zcl_attr_list_create (ESP_ZB_ZCL_CLUSTER_ID_TIME);
276
305
// Add time clusters to cluster list
277
- esp_zb_cluster_list_add_time_cluster (_cluster_list, time_cluster_server, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
278
- esp_zb_cluster_list_add_time_cluster (_cluster_list, time_cluster_client, ESP_ZB_ZCL_CLUSTER_CLIENT_ROLE);
306
+ ret = esp_zb_cluster_list_add_time_cluster (_cluster_list, time_cluster_server, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
307
+ if (ret != ESP_OK) {
308
+ log_e (" Failed to add time cluster (server role): 0x%x: %s" , ret, esp_err_to_name (ret));
309
+ return false ;
310
+ }
311
+ ret = esp_zb_cluster_list_add_time_cluster (_cluster_list, time_cluster_client, ESP_ZB_ZCL_CLUSTER_CLIENT_ROLE);
312
+ if (ret != ESP_OK) {
313
+ log_e (" Failed to add time cluster (client role): 0x%x: %s" , ret, esp_err_to_name (ret));
314
+ return false ;
315
+ }
316
+ return true ;
279
317
}
280
318
281
319
bool ZigbeeEP::setTime (tm time) {
0 commit comments