Skip to content

Commit 909606a

Browse files
committed
fix(zigbee): Return false on first error hit
1 parent 65b9383 commit 909606a

14 files changed

+214
-115
lines changed

libraries/Zigbee/src/ZigbeeCore.cpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,26 @@ bool ZigbeeCore::begin(zigbee_role_t role, bool erase_nvs) {
9191
return started();
9292
}
9393

94-
void ZigbeeCore::addEndpoint(ZigbeeEP *ep) {
94+
bool ZigbeeCore::addEndpoint(ZigbeeEP *ep) {
9595
ep_objects.push_back(ep);
9696

9797
log_d("Endpoint: %d, Device ID: 0x%04x", ep->_endpoint, ep->_device_id);
9898
//Register clusters and ep_list to the ZigbeeCore class's ep_list
9999
if (ep->_ep_config.endpoint == 0 || ep->_cluster_list == nullptr) {
100100
log_e("Endpoint config or Cluster list is not initialized, EP not added to ZigbeeCore's EP list");
101-
return;
101+
return false;
102102
}
103-
103+
esp_err_t ret = ESP_OK;
104104
if (ep->_device_id == ESP_ZB_HA_HOME_GATEWAY_DEVICE_ID) {
105-
esp_zb_ep_list_add_gateway_ep(_zb_ep_list, ep->_cluster_list, ep->_ep_config);
105+
ret = esp_zb_ep_list_add_gateway_ep(_zb_ep_list, ep->_cluster_list, ep->_ep_config);
106106
} else {
107-
esp_zb_ep_list_add_ep(_zb_ep_list, ep->_cluster_list, ep->_ep_config);
107+
ret = esp_zb_ep_list_add_ep(_zb_ep_list, ep->_cluster_list, ep->_ep_config);
108108
}
109+
if(ret != ESP_OK) {
110+
log_e("Failed to add endpoint: 0x%x: %s", ret, esp_err_to_name(ret));
111+
return false;
112+
}
113+
return true;
109114
}
110115

111116
static void esp_zb_task(void *pvParameters) {

libraries/Zigbee/src/ZigbeeCore.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class ZigbeeCore {
129129
return _role;
130130
}
131131

132-
void addEndpoint(ZigbeeEP *ep);
132+
bool addEndpoint(ZigbeeEP *ep);
133133
//void removeEndpoint(ZigbeeEP *ep);
134134

135135
void setRadioConfig(esp_zb_radio_config_t config);

libraries/Zigbee/src/ZigbeeEP.cpp

+54-16
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,28 @@ bool ZigbeeEP::setManufacturerAndModel(const char *name, const char *model) {
5555

5656
// Get the basic cluster and update the manufacturer and model attributes
5757
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;
6267
}
63-
6468
delete[] zb_name;
6569
delete[] zb_model;
66-
return ret_manufacturer == ESP_OK && ret_model == ESP_OK;
70+
return true;
6771
}
6872

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) {
7074
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+
}
7280

7381
if (power_source == ZB_POWER_SOURCE_BATTERY) {
7482
// 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
7785
}
7886
battery_percentage = battery_percentage * 2;
7987
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+
}
8298
}
8399
_power_source = power_source;
100+
return true;
84101
}
85102

86103
bool ZigbeeEP::setBatteryPercentage(uint8_t percentage) {
@@ -258,7 +275,7 @@ void ZigbeeEP::zbIdentify(const esp_zb_zcl_set_attr_value_message_t *message) {
258275
}
259276
}
260277

261-
void ZigbeeEP::addTimeCluster(tm time, int32_t gmt_offset) {
278+
bool ZigbeeEP::addTimeCluster(tm time, int32_t gmt_offset) {
262279
time_t utc_time = 0;
263280
// Check if time is set
264281
if (time.tm_year > 0) {
@@ -268,14 +285,35 @@ void ZigbeeEP::addTimeCluster(tm time, int32_t gmt_offset) {
268285

269286
// Create time cluster server attributes
270287
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+
}
274303
// Create time cluster client attributes
275304
esp_zb_attribute_list_t *time_cluster_client = esp_zb_zcl_attr_list_create(ESP_ZB_ZCL_CLUSTER_ID_TIME);
276305
// 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;
279317
}
280318

281319
bool ZigbeeEP::setTime(tm time) {

libraries/Zigbee/src/ZigbeeEP.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ class ZigbeeEP {
7777
char *readModel(uint8_t endpoint, uint16_t short_addr, esp_zb_ieee_addr_t ieee_addr);
7878

7979
// Set Power source and battery percentage for battery powered devices
80-
void setPowerSource(zb_power_source_t power_source, uint8_t percentage = 255);
80+
bool setPowerSource(zb_power_source_t power_source, uint8_t percentage = 255);
8181
bool setBatteryPercentage(uint8_t percentage);
8282
bool reportBatteryPercentage();
8383

8484
// Set time
85-
void addTimeCluster(tm time = {}, int32_t gmt_offset = 0); // gmt offset in seconds
85+
bool addTimeCluster(tm time = {}, int32_t gmt_offset = 0); // gmt offset in seconds
8686
bool setTime(tm time);
8787
bool setTimezone(int32_t gmt_offset);
8888

libraries/Zigbee/src/ep/ZigbeeCarbonDioxideSensor.cpp

+9-7
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,17 @@ bool ZigbeeCarbonDioxideSensor::setMinMaxValue(float min, float max) {
2929
float zb_max = max / 1000000.0f;
3030
esp_zb_attribute_list_t *carbon_dioxide_measure_cluster =
3131
esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_CARBON_DIOXIDE_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
32-
esp_err_t ret_min = esp_zb_cluster_update_attr(carbon_dioxide_measure_cluster, ESP_ZB_ZCL_ATTR_CARBON_DIOXIDE_MEASUREMENT_MIN_MEASURED_VALUE_ID, (void *)&zb_min);
33-
if(ret_min != ESP_OK) {
34-
log_e("Failed to set min value: 0x%x: %s", ret_min, esp_err_to_name(ret_min));
32+
esp_err_t ret = esp_zb_cluster_update_attr(carbon_dioxide_measure_cluster, ESP_ZB_ZCL_ATTR_CARBON_DIOXIDE_MEASUREMENT_MIN_MEASURED_VALUE_ID, (void *)&zb_min);
33+
if(ret != ESP_OK) {
34+
log_e("Failed to set min value: 0x%x: %s", ret, esp_err_to_name(ret));
35+
return false;
3536
}
36-
esp_err_t ret_max = esp_zb_cluster_update_attr(carbon_dioxide_measure_cluster, ESP_ZB_ZCL_ATTR_CARBON_DIOXIDE_MEASUREMENT_MAX_MEASURED_VALUE_ID, (void *)&zb_max);
37-
if(ret_max != ESP_OK) {
38-
log_e("Failed to set max value: 0x%x: %s", ret_max, esp_err_to_name(ret_max));
37+
ret = esp_zb_cluster_update_attr(carbon_dioxide_measure_cluster, ESP_ZB_ZCL_ATTR_CARBON_DIOXIDE_MEASUREMENT_MAX_MEASURED_VALUE_ID, (void *)&zb_max);
38+
if(ret != ESP_OK) {
39+
log_e("Failed to set max value: 0x%x: %s", ret, esp_err_to_name(ret));
40+
return false;
3941
}
40-
return ret_min == ESP_OK && ret_max == ESP_OK;
42+
return true;
4143
}
4244

4345
bool ZigbeeCarbonDioxideSensor::setTolerance(float tolerance) {

libraries/Zigbee/src/ep/ZigbeeColorDimmableLight.cpp

+34-12
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ void ZigbeeColorDimmableLight::lightChanged() {
118118
}
119119

120120
bool ZigbeeColorDimmableLight::setLight(bool state, uint8_t level, uint8_t red, uint8_t green, uint8_t blue) {
121+
esp_zb_zcl_status_t ret = ESP_ZB_ZCL_STATUS_SUCCESS;
121122
//Update all attributes
122123
_current_state = state;
123124
_current_level = level;
@@ -131,34 +132,55 @@ bool ZigbeeColorDimmableLight::setLight(bool state, uint8_t level, uint8_t red,
131132
/* Update light clusters */
132133
esp_zb_lock_acquire(portMAX_DELAY);
133134
//set on/off state
134-
esp_zb_zcl_status_t ret_state = esp_zb_zcl_set_attribute_val(
135+
ret = esp_zb_zcl_set_attribute_val(
135136
_endpoint, ESP_ZB_ZCL_CLUSTER_ID_ON_OFF, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID, &_current_state, false
136137
);
138+
if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
139+
log_e("Failed to set light state: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
140+
return false;
141+
}
137142
//set level
138-
esp_zb_zcl_status_t ret_level = esp_zb_zcl_set_attribute_val(
143+
ret = esp_zb_zcl_set_attribute_val(
139144
_endpoint, ESP_ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_LEVEL_CONTROL_CURRENT_LEVEL_ID, &_current_level, false
140145
);
141-
//set xy color
142-
esp_zb_zcl_status_t ret_xy = esp_zb_zcl_set_attribute_val(
146+
if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
147+
log_e("Failed to set light level: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
148+
return false;
149+
}
150+
//set x color
151+
ret = esp_zb_zcl_set_attribute_val(
143152
_endpoint, ESP_ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_X_ID, &xy_color.x, false
144153
);
145-
esp_zb_zcl_status_t ret_y = esp_zb_zcl_set_attribute_val(
154+
if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
155+
log_e("Failed to set light xy color: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
156+
return false;
157+
}
158+
//set y color
159+
ret = esp_zb_zcl_set_attribute_val(
146160
_endpoint, ESP_ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_Y_ID, &xy_color.y, false
147161
);
148-
//set hsv color
162+
if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
163+
log_e("Failed to set light y color: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
164+
return false;
165+
}
166+
//set hue
149167
uint8_t hue = (uint8_t)hsv_color.h;
150-
esp_zb_zcl_status_t ret_hue = esp_zb_zcl_set_attribute_val(
168+
ret = esp_zb_zcl_set_attribute_val(
151169
_endpoint, ESP_ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_HUE_ID, &hue, false
152170
);
153-
esp_zb_zcl_status_t ret_saturation = esp_zb_zcl_set_attribute_val(
171+
if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
172+
log_e("Failed to set light hue: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
173+
return false;
174+
}
175+
//set saturation
176+
ret = esp_zb_zcl_set_attribute_val(
154177
_endpoint, ESP_ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_SATURATION_ID, &hsv_color.s, false
155178
);
156-
esp_zb_lock_release();
157-
158-
if (ret_state != ESP_ZB_ZCL_STATUS_SUCCESS || ret_level != ESP_ZB_ZCL_STATUS_SUCCESS || ret_xy != ESP_ZB_ZCL_STATUS_SUCCESS || ret_y != ESP_ZB_ZCL_STATUS_SUCCESS || ret_hue != ESP_ZB_ZCL_STATUS_SUCCESS || ret_saturation != ESP_ZB_ZCL_STATUS_SUCCESS) {
159-
log_e("Failed to set light state(0x%x: %s), level(0x%x: %s), xy(0x%x: %s), y(0x%x: %s), hue(0x%x: %s), saturation(0x%x: %s)", ret_state, esp_zb_zcl_status_to_name(ret_state), ret_level, esp_zb_zcl_status_to_name(ret_level), ret_xy, esp_zb_zcl_status_to_name(ret_xy), ret_y, esp_zb_zcl_status_to_name(ret_y), ret_hue, esp_zb_zcl_status_to_name(ret_hue), ret_saturation, esp_zb_zcl_status_to_name(ret_saturation));
179+
if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
180+
log_e("Failed to set light saturation: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
160181
return false;
161182
}
183+
esp_zb_lock_release();
162184
return true;
163185
}
164186

libraries/Zigbee/src/ep/ZigbeeDimmableLight.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ void ZigbeeDimmableLight::lightChanged() {
5252
}
5353

5454
bool ZigbeeDimmableLight::setLight(bool state, uint8_t level) {
55+
esp_zb_zcl_status_t ret = ESP_ZB_ZCL_STATUS_SUCCESS;
5556
// Update all attributes
5657
_current_state = state;
5758
_current_level = level;
@@ -61,19 +62,22 @@ bool ZigbeeDimmableLight::setLight(bool state, uint8_t level) {
6162
/* Update light clusters */
6263
esp_zb_lock_acquire(portMAX_DELAY);
6364
// set on/off state
64-
esp_zb_zcl_status_t ret_state = esp_zb_zcl_set_attribute_val(
65+
ret = esp_zb_zcl_set_attribute_val(
6566
_endpoint, ESP_ZB_ZCL_CLUSTER_ID_ON_OFF, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID, &_current_state, false
6667
);
68+
if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
69+
log_e("Failed to set light state: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
70+
return false;
71+
}
6772
// set level
68-
esp_zb_zcl_status_t ret_level = esp_zb_zcl_set_attribute_val(
73+
ret = esp_zb_zcl_set_attribute_val(
6974
_endpoint, ESP_ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_LEVEL_CONTROL_CURRENT_LEVEL_ID, &_current_level, false
7075
);
71-
esp_zb_lock_release();
72-
73-
if (ret_state != ESP_ZB_ZCL_STATUS_SUCCESS || ret_level != ESP_ZB_ZCL_STATUS_SUCCESS) {
74-
log_e("Failed to set light state(0x%x: %s) or level(0x%x: %s)", ret_state, esp_zb_zcl_status_to_name(ret_state), ret_level, esp_zb_zcl_status_to_name(ret_level));
76+
if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
77+
log_e("Failed to set light level: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
7578
return false;
7679
}
80+
esp_zb_lock_release();
7781
return true;
7882
}
7983

libraries/Zigbee/src/ep/ZigbeeFlowSensor.cpp

+9-7
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,17 @@ bool ZigbeeFlowSensor::setMinMaxValue(float min, float max) {
3131
log_e("Failed to get flow measurement cluster");
3232
return false;
3333
}
34-
esp_err_t ret_min = esp_zb_cluster_update_attr(flow_measure_cluster, ESP_ZB_ZCL_ATTR_FLOW_MEASUREMENT_MIN_VALUE_ID, (void *)&zb_min);
35-
if(ret_min != ESP_OK) {
36-
log_e("Failed to set min value: 0x%x: %s", ret_min, esp_err_to_name(ret_min));
34+
esp_err_t ret = esp_zb_cluster_update_attr(flow_measure_cluster, ESP_ZB_ZCL_ATTR_FLOW_MEASUREMENT_MIN_VALUE_ID, (void *)&zb_min);
35+
if(ret != ESP_OK) {
36+
log_e("Failed to set min value: 0x%x: %s", ret, esp_err_to_name(ret));
37+
return false;
3738
}
38-
esp_err_t ret_max = esp_zb_cluster_update_attr(flow_measure_cluster, ESP_ZB_ZCL_ATTR_FLOW_MEASUREMENT_MAX_VALUE_ID, (void *)&zb_max);
39-
if(ret_max != ESP_OK) {
40-
log_e("Failed to set max value: 0x%x: %s", ret_max, esp_err_to_name(ret_max));
39+
ret = esp_zb_cluster_update_attr(flow_measure_cluster, ESP_ZB_ZCL_ATTR_FLOW_MEASUREMENT_MAX_VALUE_ID, (void *)&zb_max);
40+
if(ret != ESP_OK) {
41+
log_e("Failed to set max value: 0x%x: %s", ret, esp_err_to_name(ret));
42+
return false;
4143
}
42-
return ret_min == ESP_OK && ret_max == ESP_OK;
44+
return true;
4345
}
4446

4547
bool ZigbeeFlowSensor::setTolerance(float tolerance) {

libraries/Zigbee/src/ep/ZigbeeIlluminanceSensor.cpp

+9-7
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ bool ZigbeeIlluminanceSensor::setMinMaxValue(uint16_t min, uint16_t max) {
1717
log_e("Failed to get illuminance measurement cluster");
1818
return false;
1919
}
20-
esp_err_t ret_min = esp_zb_cluster_update_attr(light_measure_cluster, ESP_ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MIN_MEASURED_VALUE_ID, (void *)&min);
21-
if (ret_min != ESP_OK) {
22-
log_e("Failed to set min value: 0x%x: %s", ret_min, esp_err_to_name(ret_min));
20+
esp_err_t ret = esp_zb_cluster_update_attr(light_measure_cluster, ESP_ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MIN_MEASURED_VALUE_ID, (void *)&min);
21+
if (ret != ESP_OK) {
22+
log_e("Failed to set min value: 0x%x: %s", ret, esp_err_to_name(ret));
23+
return false;
2324
}
24-
esp_err_t ret_max = esp_zb_cluster_update_attr(light_measure_cluster, ESP_ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MAX_MEASURED_VALUE_ID, (void *)&max);
25-
if (ret_max != ESP_OK) {
26-
log_e("Failed to set max value: 0x%x: %s", ret_max, esp_err_to_name(ret_max));
25+
ret = esp_zb_cluster_update_attr(light_measure_cluster, ESP_ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MAX_MEASURED_VALUE_ID, (void *)&max);
26+
if (ret != ESP_OK) {
27+
log_e("Failed to set max value: 0x%x: %s", ret, esp_err_to_name(ret));
28+
return false;
2729
}
28-
return ret_min == ESP_OK && ret_max == ESP_OK;
30+
return true;
2931
}
3032

3133
bool ZigbeeIlluminanceSensor::setTolerance(uint16_t tolerance) {

libraries/Zigbee/src/ep/ZigbeeOccupancySensor.cpp

+9-7
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,17 @@ bool ZigbeeOccupancySensor::setSensorType(uint8_t sensor_type) {
2626
uint8_t sensor_type_bitmap = 1 << sensor_type;
2727
esp_zb_attribute_list_t *occupancy_sens_cluster =
2828
esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_OCCUPANCY_SENSING, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
29-
esp_err_t ret_type = esp_zb_cluster_update_attr(occupancy_sens_cluster, ESP_ZB_ZCL_ATTR_OCCUPANCY_SENSING_OCCUPANCY_SENSOR_TYPE_ID, (void *)&sensor_type);
30-
if(ret_type != ESP_OK) {
31-
log_e("Failed to set sensor type: 0x%x: %s", ret_type, esp_err_to_name(ret_type));
29+
esp_err_t ret = esp_zb_cluster_update_attr(occupancy_sens_cluster, ESP_ZB_ZCL_ATTR_OCCUPANCY_SENSING_OCCUPANCY_SENSOR_TYPE_ID, (void *)&sensor_type);
30+
if(ret != ESP_OK) {
31+
log_e("Failed to set sensor type: 0x%x: %s", ret, esp_err_to_name(ret));
32+
return false;
3233
}
33-
esp_err_t ret_bitmap = esp_zb_cluster_update_attr(occupancy_sens_cluster, ESP_ZB_ZCL_ATTR_OCCUPANCY_SENSING_OCCUPANCY_SENSOR_TYPE_BITMAP_ID, (void *)&sensor_type_bitmap);
34-
if(ret_bitmap != ESP_OK) {
35-
log_e("Failed to set sensor type bitmap: 0x%x: %s", ret_bitmap, esp_err_to_name(ret_bitmap));
34+
ret = esp_zb_cluster_update_attr(occupancy_sens_cluster, ESP_ZB_ZCL_ATTR_OCCUPANCY_SENSING_OCCUPANCY_SENSOR_TYPE_BITMAP_ID, (void *)&sensor_type_bitmap);
35+
if(ret != ESP_OK) {
36+
log_e("Failed to set sensor type bitmap: 0x%x: %s", ret, esp_err_to_name(ret));
37+
return false;
3638
}
37-
return ret_type == ESP_OK && ret_bitmap == ESP_OK;
39+
return true;
3840
}
3941

4042
bool ZigbeeOccupancySensor::setOccupancy(bool occupied) {

0 commit comments

Comments
 (0)