Skip to content

Commit 9330f1f

Browse files
authored
Clamp Zigbee color saturation to 0-254
1 parent 21640ac commit 9330f1f

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

libraries/Zigbee/src/ep/ZigbeeColorDimmableLight.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ bool ZigbeeColorDimmableLight::setLight(bool state, uint8_t level, uint8_t red,
128128
espXyColor_t xy_color = espRgbColorToXYColor(_current_color);
129129
espHsvColor_t hsv_color = espRgbColorToHsvColor(_current_color);
130130
uint8_t hue = (uint8_t)hsv_color.h;
131+
uint8_t saturation = (hsv_color.s > 254) ? 254 : (uint8_t)hsv_color.s; // Clamp to 0-254 (per the Zigbee standard)
131132

132133
log_v("Updating light state: %d, level: %d, color: %d, %d, %d", state, level, red, green, blue);
133134
/* Update light clusters */
@@ -174,7 +175,7 @@ bool ZigbeeColorDimmableLight::setLight(bool state, uint8_t level, uint8_t red,
174175
}
175176
//set saturation
176177
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
178+
_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
178179
);
179180
if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
180181
log_e("Failed to set light saturation: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret));

0 commit comments

Comments
 (0)