Skip to content

feat(zigbee): Add check, boolean returns, fix Analog, add optional reset on factoryReset #11153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(zigbee): release locks before returning
  • Loading branch information
P-R-O-C-H-Y committed Mar 27, 2025
commit b6bf3c21cf17ac8e43e555ac71b157a0c1e51282
17 changes: 9 additions & 8 deletions libraries/Zigbee/src/ep/ZigbeeColorDimmableLight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ bool ZigbeeColorDimmableLight::setLight(bool state, uint8_t level, uint8_t red,

espXyColor_t xy_color = espRgbColorToXYColor(_current_color);
espHsvColor_t hsv_color = espRgbColorToHsvColor(_current_color);
uint8_t hue = (uint8_t)hsv_color.h;

log_v("Updating light state: %d, level: %d, color: %d, %d, %d", state, level, red, green, blue);
/* Update light clusters */
Expand All @@ -137,51 +138,51 @@ bool ZigbeeColorDimmableLight::setLight(bool state, uint8_t level, uint8_t red,
);
if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
log_e("Failed to set light state: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
return false;
goto unlock_and_return;
}
//set level
ret = esp_zb_zcl_set_attribute_val(
_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
);
if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
log_e("Failed to set light level: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
return false;
goto unlock_and_return;
}
//set x color
ret = esp_zb_zcl_set_attribute_val(
_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
);
if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
log_e("Failed to set light xy color: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
return false;
goto unlock_and_return;
}
//set y color
ret = esp_zb_zcl_set_attribute_val(
_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
);
if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
log_e("Failed to set light y color: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
return false;
goto unlock_and_return;
}
//set hue
uint8_t hue = (uint8_t)hsv_color.h;
ret = esp_zb_zcl_set_attribute_val(
_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
);
if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
log_e("Failed to set light hue: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
return false;
goto unlock_and_return;
}
//set saturation
ret = esp_zb_zcl_set_attribute_val(
_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
);
if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
log_e("Failed to set light saturation: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
return false;
goto unlock_and_return;
}
unlock_and_return:
esp_zb_lock_release();
return true;
return ret == ESP_ZB_ZCL_STATUS_SUCCESS;
}

bool ZigbeeColorDimmableLight::setLightState(bool state) {
Expand Down
7 changes: 4 additions & 3 deletions libraries/Zigbee/src/ep/ZigbeeDimmableLight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,19 @@ bool ZigbeeDimmableLight::setLight(bool state, uint8_t level) {
);
if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
log_e("Failed to set light state: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
return false;
goto unlock_and_return;
}
// set level
ret = esp_zb_zcl_set_attribute_val(
_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
);
if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
log_e("Failed to set light level: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
return false;
goto unlock_and_return;
}
unlock_and_return:
esp_zb_lock_release();
return true;
return ret == ESP_ZB_ZCL_STATUS_SUCCESS;
}

bool ZigbeeDimmableLight::setLightState(bool state) {
Expand Down
28 changes: 16 additions & 12 deletions libraries/Zigbee/src/ep/ZigbeeWindowCovering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,18 +282,19 @@ bool ZigbeeWindowCovering::setLiftPosition(uint16_t lift_position) {
);
if(ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
log_e("Failed to set lift position: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
return false;
goto unlock_and_return;
}
ret = esp_zb_zcl_set_attribute_val(
_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,
&_current_lift_percentage, false
);
if(ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
log_e("Failed to set lift percentage: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
return false;
goto unlock_and_return;
}
unlock_and_return:
esp_zb_lock_release();
return true;
return ret == ESP_ZB_ZCL_STATUS_SUCCESS;
}

bool ZigbeeWindowCovering::setLiftPercentage(uint8_t lift_percentage) {
Expand All @@ -310,18 +311,19 @@ bool ZigbeeWindowCovering::setLiftPercentage(uint8_t lift_percentage) {
);
if(ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
log_e("Failed to set lift position: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
return false;
goto unlock_and_return;
}
ret = esp_zb_zcl_set_attribute_val(
_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,
&_current_lift_percentage, false
);
if(ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
log_e("Failed to set lift percentage: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
return false;
goto unlock_and_return;
}
unlock_and_return:
esp_zb_lock_release();
return true;
return ret == ESP_ZB_ZCL_STATUS_SUCCESS;
}

bool ZigbeeWindowCovering::setTiltPosition(uint16_t tilt_position) {
Expand All @@ -339,18 +341,19 @@ bool ZigbeeWindowCovering::setTiltPosition(uint16_t tilt_position) {
);
if(ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
log_e("Failed to set tilt position: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
return false;
goto unlock_and_return;
}
ret = esp_zb_zcl_set_attribute_val(
_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,
&_current_tilt_percentage, false
);
if(ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
log_e("Failed to set tilt percentage: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
return false;
goto unlock_and_return;
}
unlock_and_return:
esp_zb_lock_release();
return true;
return ret == ESP_ZB_ZCL_STATUS_SUCCESS;
}

bool ZigbeeWindowCovering::setTiltPercentage(uint8_t tilt_percentage) {
Expand All @@ -368,18 +371,19 @@ bool ZigbeeWindowCovering::setTiltPercentage(uint8_t tilt_percentage) {
);
if(ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
log_e("Failed to set tilt position: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
return false;
goto unlock_and_return;
}
ret = esp_zb_zcl_set_attribute_val(
_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,
&_current_tilt_percentage, false
);
if(ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
log_e("Failed to set tilt percentage: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));
return false;
goto unlock_and_return;
}
unlock_and_return:
esp_zb_lock_release();
return true;
return ret == ESP_ZB_ZCL_STATUS_SUCCESS;
}

#endif // CONFIG_ZB_ENABLED
Loading