Skip to content

Commit 6474127

Browse files
Update ZigbeeColorDimmableLight to clamp color hue and saturation to 0-254 (Fixes #11527) (#11528)
* Clamp Zigbee color saturation to 0-254 * Clamp hue to 0-254 for Zigbee color lights * Use std::min instead of ternary operator * ci(pre-commit): Apply automatic fixes --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 7f75e44 commit 6474127

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

libraries/Zigbee/src/ep/ZigbeeColorDimmableLight.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <algorithm>
12
#include "ZigbeeColorDimmableLight.h"
23
#if CONFIG_ZB_ENABLED
34

@@ -127,7 +128,8 @@ bool ZigbeeColorDimmableLight::setLight(bool state, uint8_t level, uint8_t red,
127128

128129
espXyColor_t xy_color = espRgbColorToXYColor(_current_color);
129130
espHsvColor_t hsv_color = espRgbColorToHsvColor(_current_color);
130-
uint8_t hue = (uint8_t)hsv_color.h;
131+
uint8_t hue = std::min((uint8_t)hsv_color.h, (uint8_t)254); // Clamp to 0-254
132+
uint8_t saturation = std::min((uint8_t)hsv_color.s, (uint8_t)254); // Clamp to 0-254
131133

132134
log_v("Updating light state: %d, level: %d, color: %d, %d, %d", state, level, red, green, blue);
133135
/* Update light clusters */
@@ -174,7 +176,7 @@ bool ZigbeeColorDimmableLight::setLight(bool state, uint8_t level, uint8_t red,
174176
}
175177
//set saturation
176178
ret = esp_zb_zcl_set_attribute_val(
177-
_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
179+
_endpoint, ESP_ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_SATURATION_ID, &saturation, false
178180
);
179181
if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
180182
log_e("Failed to set light saturation: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));

0 commit comments

Comments
 (0)