@@ -50,8 +50,8 @@ ZigbeeColorDimmableLight::ZigbeeColorDimmableLight(uint8_t endpoint) : ZigbeeEP(
5050 _current_color = {255 , 255 , 255 };
5151 _current_hsv = {0 , 0 , 255 };
5252 _current_color_temperature = ESP_ZB_ZCL_COLOR_CONTROL_COLOR_TEMPERATURE_DEF_VALUE;
53- _current_color_mode = ZIGBEE_COLOR_MODE_CURRENT_X_Y; // default XY color mode
54- _color_capabilities = ZIGBEE_COLOR_CAPABILITY_X_Y; // default XY color supported only
53+ _current_color_mode = ZIGBEE_COLOR_MODE_CURRENT_X_Y; // default XY color mode
54+ _color_capabilities = ZIGBEE_COLOR_CAPABILITY_X_Y; // default XY color supported only
5555
5656 // Initialize callbacks to nullptr
5757 _on_light_change_rgb = nullptr ;
@@ -128,13 +128,13 @@ void ZigbeeColorDimmableLight::zbAttributeSet(const esp_zb_zcl_set_attr_value_me
128128 log_w (" Invalid color mode received: %d" , new_color_mode);
129129 return ;
130130 }
131-
131+
132132 // Validate that the requested color mode is supported by capabilities
133133 if (!isColorModeSupported (new_color_mode)) {
134134 log_w (" Color mode %d not supported by current capabilities: 0x%04x" , new_color_mode, _color_capabilities);
135135 return ;
136136 }
137-
137+
138138 _current_color_mode = new_color_mode;
139139 log_v (" Color mode changed to: %d" , _current_color_mode);
140140 // Don't call setLightColorMode() here - the attribute was already set externally
@@ -187,7 +187,7 @@ void ZigbeeColorDimmableLight::zbAttributeSet(const esp_zb_zcl_set_attr_value_me
187187 // Store HSV values and call HSV callback (don't convert to RGB)
188188 _current_hsv.h = light_color_hue;
189189 _current_hsv.s = getCurrentColorSaturation ();
190- _current_hsv.v = _current_level; // Use level as value
190+ _current_hsv.v = _current_level; // Use level as value
191191 lightChangedHsv ();
192192 return ;
193193 } else if (message->attribute .id == ESP_ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_SATURATION_ID && message->attribute .data .type == ESP_ZB_ZCL_ATTR_TYPE_U8) {
@@ -204,7 +204,7 @@ void ZigbeeColorDimmableLight::zbAttributeSet(const esp_zb_zcl_set_attr_value_me
204204 // Store HSV values and call HSV callback (don't convert to RGB)
205205 _current_hsv.h = getCurrentColorHue ();
206206 _current_hsv.s = light_color_saturation;
207- _current_hsv.v = _current_level; // Use level as value
207+ _current_hsv.v = _current_level; // Use level as value
208208 lightChangedHsv ();
209209 return ;
210210 } else if (message->attribute .id == ESP_ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_TEMPERATURE_ID && message->attribute .data .type == ESP_ZB_ZCL_ATTR_TYPE_U16) {
@@ -252,18 +252,10 @@ void ZigbeeColorDimmableLight::lightChangedTemp() {
252252void ZigbeeColorDimmableLight::lightChangedByMode () {
253253 // Call the appropriate callback based on current color mode
254254 switch (_current_color_mode) {
255- case ZIGBEE_COLOR_MODE_CURRENT_X_Y:
256- lightChangedRgb ();
257- break ;
258- case ZIGBEE_COLOR_MODE_HUE_SATURATION:
259- lightChangedHsv ();
260- break ;
261- case ZIGBEE_COLOR_MODE_TEMPERATURE:
262- lightChangedTemp ();
263- break ;
264- default :
265- log_e (" Unknown color mode: %d" , _current_color_mode);
266- break ;
255+ case ZIGBEE_COLOR_MODE_CURRENT_X_Y: lightChangedRgb (); break ;
256+ case ZIGBEE_COLOR_MODE_HUE_SATURATION: lightChangedHsv (); break ;
257+ case ZIGBEE_COLOR_MODE_TEMPERATURE: lightChangedTemp (); break ;
258+ default : log_e (" Unknown color mode: %d" , _current_color_mode); break ;
267259 }
268260}
269261
@@ -352,48 +344,48 @@ bool ZigbeeColorDimmableLight::setLightState(bool state) {
352344 if (_current_state == state) {
353345 return true ; // No change needed
354346 }
355-
347+
356348 _current_state = state;
357349 esp_zb_zcl_status_t ret = ESP_ZB_ZCL_STATUS_SUCCESS;
358350 esp_zb_lock_acquire (portMAX_DELAY);
359351 ret = esp_zb_zcl_set_attribute_val (
360352 _endpoint, ESP_ZB_ZCL_CLUSTER_ID_ON_OFF, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID, &_current_state, false
361353 );
362354 esp_zb_lock_release ();
363-
355+
364356 if (ret == ESP_ZB_ZCL_STATUS_SUCCESS) {
365357 lightChangedByMode (); // Call appropriate callback based on current color mode
366358 } else {
367359 log_e (" Failed to set light state: 0x%x: %s" , ret, esp_zb_zcl_status_to_name (ret));
368360 }
369-
361+
370362 return ret == ESP_ZB_ZCL_STATUS_SUCCESS;
371363}
372364
373365bool ZigbeeColorDimmableLight::setLightLevel (uint8_t level) {
374366 if (_current_level == level) {
375367 return true ; // No change needed
376368 }
377-
369+
378370 _current_level = level;
379371 // Update HSV value if in HSV mode
380372 if (_current_color_mode == ZIGBEE_COLOR_MODE_HUE_SATURATION) {
381373 _current_hsv.v = level;
382374 }
383-
375+
384376 esp_zb_zcl_status_t ret = ESP_ZB_ZCL_STATUS_SUCCESS;
385377 esp_zb_lock_acquire (portMAX_DELAY);
386378 ret = esp_zb_zcl_set_attribute_val (
387379 _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
388380 );
389381 esp_zb_lock_release ();
390-
382+
391383 if (ret == ESP_ZB_ZCL_STATUS_SUCCESS) {
392384 lightChangedByMode (); // Call appropriate callback based on current color mode
393385 } else {
394386 log_e (" Failed to set light level: 0x%x: %s" , ret, esp_zb_zcl_status_to_name (ret));
395387 }
396-
388+
397389 return ret == ESP_ZB_ZCL_STATUS_SUCCESS;
398390}
399391
@@ -411,7 +403,7 @@ bool ZigbeeColorDimmableLight::setLightColor(espHsvColor_t hsv_color) {
411403 log_e (" Hue/Saturation color capability not enabled. Current capabilities: 0x%04x" , _color_capabilities);
412404 return false ;
413405 }
414-
406+
415407 esp_zb_zcl_status_t ret = ESP_ZB_ZCL_STATUS_SUCCESS;
416408 if (!setLightColorMode (ZIGBEE_COLOR_MODE_HUE_SATURATION)) {
417409 log_e (" Failed to set light color mode: %d" , ZIGBEE_COLOR_MODE_HUE_SATURATION);
@@ -478,7 +470,8 @@ bool ZigbeeColorDimmableLight::setLightColorTemperature(uint16_t color_temperatu
478470 /* Update light clusters */
479471 esp_zb_lock_acquire (portMAX_DELAY);
480472 ret = esp_zb_zcl_set_attribute_val (
481- _endpoint, ESP_ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_TEMPERATURE_ID, &_current_color_temperature, false
473+ _endpoint, ESP_ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_TEMPERATURE_ID,
474+ &_current_color_temperature, false
482475 );
483476 if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
484477 log_e (" Failed to set light color temperature: 0x%x: %s" , ret, esp_zb_zcl_status_to_name (ret));
@@ -491,14 +484,10 @@ bool ZigbeeColorDimmableLight::setLightColorTemperature(uint16_t color_temperatu
491484
492485bool ZigbeeColorDimmableLight::isColorModeSupported (uint8_t color_mode) {
493486 switch (color_mode) {
494- case ZIGBEE_COLOR_MODE_CURRENT_X_Y:
495- return (_color_capabilities & ZIGBEE_COLOR_CAPABILITY_X_Y) != 0 ;
496- case ZIGBEE_COLOR_MODE_HUE_SATURATION:
497- return (_color_capabilities & ZIGBEE_COLOR_CAPABILITY_HUE_SATURATION) != 0 ;
498- case ZIGBEE_COLOR_MODE_TEMPERATURE:
499- return (_color_capabilities & ZIGBEE_COLOR_CAPABILITY_COLOR_TEMP) != 0 ;
500- default :
501- return false ;
487+ case ZIGBEE_COLOR_MODE_CURRENT_X_Y: return (_color_capabilities & ZIGBEE_COLOR_CAPABILITY_X_Y) != 0 ;
488+ case ZIGBEE_COLOR_MODE_HUE_SATURATION: return (_color_capabilities & ZIGBEE_COLOR_CAPABILITY_HUE_SATURATION) != 0 ;
489+ case ZIGBEE_COLOR_MODE_TEMPERATURE: return (_color_capabilities & ZIGBEE_COLOR_CAPABILITY_COLOR_TEMP) != 0 ;
490+ default : return false ;
502491 }
503492}
504493
@@ -507,13 +496,13 @@ bool ZigbeeColorDimmableLight::setLightColorMode(uint8_t color_mode) {
507496 log_e (" Invalid color mode: %d" , color_mode);
508497 return false ;
509498 }
510-
499+
511500 // Check if the requested color mode is supported by capabilities
512501 if (!isColorModeSupported (color_mode)) {
513502 log_e (" Color mode %d not supported by current capabilities: 0x%04x" , color_mode, _color_capabilities);
514503 return false ;
515504 }
516-
505+
517506 esp_zb_zcl_status_t ret = ESP_ZB_ZCL_STATUS_SUCCESS;
518507 log_v (" Setting color mode: %d" , color_mode);
519508 esp_zb_lock_acquire (portMAX_DELAY);
@@ -535,21 +524,21 @@ bool ZigbeeColorDimmableLight::setLightColorCapabilities(uint16_t capabilities)
535524 log_e (" Color control cluster not found" );
536525 return false ;
537526 }
538-
527+
539528 // Validate capabilities (max value is 0x001f per ZCL spec)
540529 if (capabilities > 0x001f ) {
541530 log_e (" Invalid color capabilities value: 0x%04x (max: 0x001f)" , capabilities);
542531 return false ;
543532 }
544-
533+
545534 _color_capabilities = capabilities;
546-
535+
547536 esp_err_t ret = esp_zb_cluster_update_attr (color_cluster, ESP_ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_CAPABILITIES_ID, &_color_capabilities);
548537 if (ret != ESP_OK) {
549538 log_e (" Failed to set color capabilities: 0x%x: %s" , ret, esp_err_to_name (ret));
550539 return false ;
551540 }
552-
541+
553542 log_v (" Color capabilities set to: 0x%04x" , _color_capabilities);
554543 return true ;
555544}
0 commit comments