From 9330f1feb617c427dc0b9b82450bf04453649b05 Mon Sep 17 00:00:00 2001 From: John Date: Sun, 29 Jun 2025 10:09:55 -0400 Subject: [PATCH 1/4] Clamp Zigbee color saturation to 0-254 --- libraries/Zigbee/src/ep/ZigbeeColorDimmableLight.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/Zigbee/src/ep/ZigbeeColorDimmableLight.cpp b/libraries/Zigbee/src/ep/ZigbeeColorDimmableLight.cpp index caac73b5c68..6ce94143e4f 100644 --- a/libraries/Zigbee/src/ep/ZigbeeColorDimmableLight.cpp +++ b/libraries/Zigbee/src/ep/ZigbeeColorDimmableLight.cpp @@ -128,6 +128,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; + uint8_t saturation = (hsv_color.s > 254) ? 254 : (uint8_t)hsv_color.s; // Clamp to 0-254 (per the Zigbee standard) log_v("Updating light state: %d, level: %d, color: %d, %d, %d", state, level, red, green, blue); /* Update light clusters */ @@ -174,7 +175,7 @@ bool ZigbeeColorDimmableLight::setLight(bool state, uint8_t level, uint8_t red, } //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 + _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 ); 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)); From 73dde095a36023c7a91f04ed61f62dcb70eeb6a7 Mon Sep 17 00:00:00 2001 From: John Date: Sun, 29 Jun 2025 11:16:16 -0400 Subject: [PATCH 2/4] Clamp hue to 0-254 for Zigbee color lights --- libraries/Zigbee/src/ep/ZigbeeColorDimmableLight.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/Zigbee/src/ep/ZigbeeColorDimmableLight.cpp b/libraries/Zigbee/src/ep/ZigbeeColorDimmableLight.cpp index 6ce94143e4f..6cb043661d8 100644 --- a/libraries/Zigbee/src/ep/ZigbeeColorDimmableLight.cpp +++ b/libraries/Zigbee/src/ep/ZigbeeColorDimmableLight.cpp @@ -127,7 +127,8 @@ 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; + uint8_t hue = (uint8_t)hsv_color.h; // Recast from uint16 to uint8 + hue = (hue > 254) ? 254 : hue; // Clamp to 0-254 (per the Zigbee standard) uint8_t saturation = (hsv_color.s > 254) ? 254 : (uint8_t)hsv_color.s; // Clamp to 0-254 (per the Zigbee standard) log_v("Updating light state: %d, level: %d, color: %d, %d, %d", state, level, red, green, blue); From 020aedd4c3b8ff10bf4724e76100b3e970eceac2 Mon Sep 17 00:00:00 2001 From: John Date: Sun, 29 Jun 2025 17:30:21 -0400 Subject: [PATCH 3/4] Use std::min instead of ternary operator --- libraries/Zigbee/src/ep/ZigbeeColorDimmableLight.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/Zigbee/src/ep/ZigbeeColorDimmableLight.cpp b/libraries/Zigbee/src/ep/ZigbeeColorDimmableLight.cpp index 6cb043661d8..4ce6c6e4de7 100644 --- a/libraries/Zigbee/src/ep/ZigbeeColorDimmableLight.cpp +++ b/libraries/Zigbee/src/ep/ZigbeeColorDimmableLight.cpp @@ -1,3 +1,4 @@ +#include #include "ZigbeeColorDimmableLight.h" #if CONFIG_ZB_ENABLED @@ -127,9 +128,8 @@ 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; // Recast from uint16 to uint8 - hue = (hue > 254) ? 254 : hue; // Clamp to 0-254 (per the Zigbee standard) - uint8_t saturation = (hsv_color.s > 254) ? 254 : (uint8_t)hsv_color.s; // Clamp to 0-254 (per the Zigbee standard) + uint8_t hue = std::min((uint8_t)hsv_color.h, (uint8_t)254); // Clamp to 0-254 + uint8_t saturation = std::min((uint8_t)hsv_color.s, (uint8_t)254); // Clamp to 0-254 log_v("Updating light state: %d, level: %d, color: %d, %d, %d", state, level, red, green, blue); /* Update light clusters */ From de332e1635e0ea8bb2c65696ca9c3a0b5e50fca2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Wed, 2 Jul 2025 11:57:01 +0000 Subject: [PATCH 4/4] ci(pre-commit): Apply automatic fixes --- libraries/Zigbee/src/ep/ZigbeeColorDimmableLight.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/Zigbee/src/ep/ZigbeeColorDimmableLight.cpp b/libraries/Zigbee/src/ep/ZigbeeColorDimmableLight.cpp index 4ce6c6e4de7..2fb07fc2187 100644 --- a/libraries/Zigbee/src/ep/ZigbeeColorDimmableLight.cpp +++ b/libraries/Zigbee/src/ep/ZigbeeColorDimmableLight.cpp @@ -128,8 +128,8 @@ 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 = std::min((uint8_t)hsv_color.h, (uint8_t)254); // Clamp to 0-254 - uint8_t saturation = std::min((uint8_t)hsv_color.s, (uint8_t)254); // Clamp to 0-254 + uint8_t hue = std::min((uint8_t)hsv_color.h, (uint8_t)254); // Clamp to 0-254 + uint8_t saturation = std::min((uint8_t)hsv_color.s, (uint8_t)254); // Clamp to 0-254 log_v("Updating light state: %d, level: %d, color: %d, %d, %d", state, level, red, green, blue); /* Update light clusters */