Skip to content

Commit b6bf3c2

Browse files
committed
fix(zigbee): release locks before returning
1 parent 282ccc5 commit b6bf3c2

File tree

3 files changed

+29
-23
lines changed

3 files changed

+29
-23
lines changed

Diff for: libraries/Zigbee/src/ep/ZigbeeColorDimmableLight.cpp

+9-8
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ bool ZigbeeColorDimmableLight::setLight(bool state, uint8_t level, uint8_t red,
127127

128128
espXyColor_t xy_color = espRgbColorToXYColor(_current_color);
129129
espHsvColor_t hsv_color = espRgbColorToHsvColor(_current_color);
130+
uint8_t hue = (uint8_t)hsv_color.h;
130131

131132
log_v("Updating light state: %d, level: %d, color: %d, %d, %d", state, level, red, green, blue);
132133
/* Update light clusters */
@@ -137,51 +138,51 @@ bool ZigbeeColorDimmableLight::setLight(bool state, uint8_t level, uint8_t red,
137138
);
138139
if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
139140
log_e("Failed to set light state: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
140-
return false;
141+
goto unlock_and_return;
141142
}
142143
//set level
143144
ret = esp_zb_zcl_set_attribute_val(
144145
_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
145146
);
146147
if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
147148
log_e("Failed to set light level: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
148-
return false;
149+
goto unlock_and_return;
149150
}
150151
//set x color
151152
ret = esp_zb_zcl_set_attribute_val(
152153
_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
153154
);
154155
if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
155156
log_e("Failed to set light xy color: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
156-
return false;
157+
goto unlock_and_return;
157158
}
158159
//set y color
159160
ret = esp_zb_zcl_set_attribute_val(
160161
_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
161162
);
162163
if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
163164
log_e("Failed to set light y color: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
164-
return false;
165+
goto unlock_and_return;
165166
}
166167
//set hue
167-
uint8_t hue = (uint8_t)hsv_color.h;
168168
ret = esp_zb_zcl_set_attribute_val(
169169
_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
170170
);
171171
if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
172172
log_e("Failed to set light hue: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
173-
return false;
173+
goto unlock_and_return;
174174
}
175175
//set saturation
176176
ret = esp_zb_zcl_set_attribute_val(
177177
_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
178178
);
179179
if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
180180
log_e("Failed to set light saturation: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
181-
return false;
181+
goto unlock_and_return;
182182
}
183+
unlock_and_return:
183184
esp_zb_lock_release();
184-
return true;
185+
return ret == ESP_ZB_ZCL_STATUS_SUCCESS;
185186
}
186187

187188
bool ZigbeeColorDimmableLight::setLightState(bool state) {

Diff for: libraries/Zigbee/src/ep/ZigbeeDimmableLight.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,19 @@ bool ZigbeeDimmableLight::setLight(bool state, uint8_t level) {
6767
);
6868
if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
6969
log_e("Failed to set light state: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
70-
return false;
70+
goto unlock_and_return;
7171
}
7272
// set level
7373
ret = esp_zb_zcl_set_attribute_val(
7474
_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
7575
);
7676
if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
7777
log_e("Failed to set light level: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
78-
return false;
78+
goto unlock_and_return;
7979
}
80+
unlock_and_return:
8081
esp_zb_lock_release();
81-
return true;
82+
return ret == ESP_ZB_ZCL_STATUS_SUCCESS;
8283
}
8384

8485
bool ZigbeeDimmableLight::setLightState(bool state) {

Diff for: libraries/Zigbee/src/ep/ZigbeeWindowCovering.cpp

+16-12
Original file line numberDiff line numberDiff line change
@@ -282,18 +282,19 @@ bool ZigbeeWindowCovering::setLiftPosition(uint16_t lift_position) {
282282
);
283283
if(ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
284284
log_e("Failed to set lift position: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
285-
return false;
285+
goto unlock_and_return;
286286
}
287287
ret = esp_zb_zcl_set_attribute_val(
288288
_endpoint, ESP_ZB_ZCL_CLUSTER_ID_WINDOW_COVERING, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_WINDOW_COVERING_CURRENT_POSITION_LIFT_PERCENTAGE_ID,
289289
&_current_lift_percentage, false
290290
);
291291
if(ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
292292
log_e("Failed to set lift percentage: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
293-
return false;
293+
goto unlock_and_return;
294294
}
295+
unlock_and_return:
295296
esp_zb_lock_release();
296-
return true;
297+
return ret == ESP_ZB_ZCL_STATUS_SUCCESS;
297298
}
298299

299300
bool ZigbeeWindowCovering::setLiftPercentage(uint8_t lift_percentage) {
@@ -310,18 +311,19 @@ bool ZigbeeWindowCovering::setLiftPercentage(uint8_t lift_percentage) {
310311
);
311312
if(ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
312313
log_e("Failed to set lift position: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
313-
return false;
314+
goto unlock_and_return;
314315
}
315316
ret = esp_zb_zcl_set_attribute_val(
316317
_endpoint, ESP_ZB_ZCL_CLUSTER_ID_WINDOW_COVERING, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_WINDOW_COVERING_CURRENT_POSITION_LIFT_PERCENTAGE_ID,
317318
&_current_lift_percentage, false
318319
);
319320
if(ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
320321
log_e("Failed to set lift percentage: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
321-
return false;
322+
goto unlock_and_return;
322323
}
324+
unlock_and_return:
323325
esp_zb_lock_release();
324-
return true;
326+
return ret == ESP_ZB_ZCL_STATUS_SUCCESS;
325327
}
326328

327329
bool ZigbeeWindowCovering::setTiltPosition(uint16_t tilt_position) {
@@ -339,18 +341,19 @@ bool ZigbeeWindowCovering::setTiltPosition(uint16_t tilt_position) {
339341
);
340342
if(ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
341343
log_e("Failed to set tilt position: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
342-
return false;
344+
goto unlock_and_return;
343345
}
344346
ret = esp_zb_zcl_set_attribute_val(
345347
_endpoint, ESP_ZB_ZCL_CLUSTER_ID_WINDOW_COVERING, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_WINDOW_COVERING_CURRENT_POSITION_TILT_PERCENTAGE_ID,
346348
&_current_tilt_percentage, false
347349
);
348350
if(ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
349351
log_e("Failed to set tilt percentage: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
350-
return false;
352+
goto unlock_and_return;
351353
}
354+
unlock_and_return:
352355
esp_zb_lock_release();
353-
return true;
356+
return ret == ESP_ZB_ZCL_STATUS_SUCCESS;
354357
}
355358

356359
bool ZigbeeWindowCovering::setTiltPercentage(uint8_t tilt_percentage) {
@@ -368,18 +371,19 @@ bool ZigbeeWindowCovering::setTiltPercentage(uint8_t tilt_percentage) {
368371
);
369372
if(ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
370373
log_e("Failed to set tilt position: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
371-
return false;
374+
goto unlock_and_return;
372375
}
373376
ret = esp_zb_zcl_set_attribute_val(
374377
_endpoint, ESP_ZB_ZCL_CLUSTER_ID_WINDOW_COVERING, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_WINDOW_COVERING_CURRENT_POSITION_TILT_PERCENTAGE_ID,
375378
&_current_tilt_percentage, false
376379
);
377380
if(ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
378381
log_e("Failed to set tilt percentage: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
379-
return false;
382+
goto unlock_and_return;
380383
}
384+
unlock_and_return:
381385
esp_zb_lock_release();
382-
return true;
386+
return ret == ESP_ZB_ZCL_STATUS_SUCCESS;
383387
}
384388

385389
#endif // CONFIG_ZB_ENABLED

0 commit comments

Comments
 (0)