|
| 1 | +#include <algorithm> |
1 | 2 | #include "ZigbeeColorDimmableLight.h" |
2 | 3 | #if CONFIG_ZB_ENABLED |
3 | 4 |
|
@@ -127,7 +128,8 @@ bool ZigbeeColorDimmableLight::setLight(bool state, uint8_t level, uint8_t red, |
127 | 128 |
|
128 | 129 | espXyColor_t xy_color = espRgbColorToXYColor(_current_color); |
129 | 130 | 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 |
131 | 133 |
|
132 | 134 | log_v("Updating light state: %d, level: %d, color: %d, %d, %d", state, level, red, green, blue); |
133 | 135 | /* Update light clusters */ |
@@ -174,7 +176,7 @@ bool ZigbeeColorDimmableLight::setLight(bool state, uint8_t level, uint8_t red, |
174 | 176 | } |
175 | 177 | //set saturation |
176 | 178 | 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 |
178 | 180 | ); |
179 | 181 | if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) { |
180 | 182 | log_e("Failed to set light saturation: 0x%x: %s", ret, esp_zb_zcl_status_to_name(ret)); |
|
0 commit comments