Skip to content

Commit c2838a8

Browse files
ci(pre-commit): Apply automatic fixes
1 parent 990eb7b commit c2838a8

File tree

4 files changed

+43
-54
lines changed

4 files changed

+43
-54
lines changed

docs/en/zigbee/ep_color_dimmable_light.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Configures which color modes are supported by the light. Must be called before s
6161
bool setLightColorCapabilities(uint16_t capabilities);
6262
6363
* ``capabilities`` - Bit flags indicating supported color modes (can be combined with bitwise OR):
64-
64+
6565
* ``ZIGBEE_COLOR_CAPABILITY_HUE_SATURATION`` - Hue/Saturation support
6666
* ``ZIGBEE_COLOR_CAPABILITY_X_Y`` - XY (RGB) support
6767
* ``ZIGBEE_COLOR_CAPABILITY_COLOR_TEMP`` - Color temperature support
@@ -76,11 +76,11 @@ Configures which color modes are supported by the light. Must be called before s
7676
light.setLightColorCapabilities(
7777
ZIGBEE_COLOR_CAPABILITY_X_Y | ZIGBEE_COLOR_CAPABILITY_COLOR_TEMP
7878
);
79-
79+
8080
// Enable all color modes
8181
light.setLightColorCapabilities(
82-
ZIGBEE_COLOR_CAPABILITY_X_Y |
83-
ZIGBEE_COLOR_CAPABILITY_HUE_SATURATION |
82+
ZIGBEE_COLOR_CAPABILITY_X_Y |
83+
ZIGBEE_COLOR_CAPABILITY_HUE_SATURATION |
8484
ZIGBEE_COLOR_CAPABILITY_COLOR_TEMP
8585
);
8686
@@ -136,7 +136,7 @@ Sets the callback function for RGB/XY color mode changes.
136136
void onLightChangeRgb(void (*callback)(bool, uint8_t, uint8_t, uint8_t, uint8_t));
137137
138138
* ``callback`` - Function pointer to the RGB light change callback (state, red, green, blue, level)
139-
139+
140140
* ``state`` - Light state (true = on, false = off)
141141
* ``red`` - Red component (0-255)
142142
* ``green`` - Green component (0-255)
@@ -155,7 +155,7 @@ Sets the callback function for HSV (Hue/Saturation) color mode changes.
155155
void onLightChangeHsv(void (*callback)(bool, uint8_t, uint8_t, uint8_t));
156156
157157
* ``callback`` - Function pointer to the HSV light change callback (state, hue, saturation, value)
158-
158+
159159
* ``state`` - Light state (true = on, false = off)
160160
* ``hue`` - Hue component (0-254)
161161
* ``saturation`` - Saturation component (0-254)
@@ -173,7 +173,7 @@ Sets the callback function for color temperature mode changes.
173173
void onLightChangeTemp(void (*callback)(bool, uint8_t, uint16_t));
174174
175175
* ``callback`` - Function pointer to the temperature light change callback (state, level, temperature_mireds)
176-
176+
177177
* ``state`` - Light state (true = on, false = off)
178178
* ``level`` - Brightness level (0-255)
179179
* ``temperature_mireds`` - Color temperature in mireds (inverse of Kelvin)
@@ -255,7 +255,7 @@ Sets the light color temperature in mireds. Requires ``ZIGBEE_COLOR_CAPABILITY_C
255255
// Set to 4000K (cool white)
256256
uint16_t mireds = 1000000 / 4000; // = 250 mireds
257257
light.setLightColorTemperature(mireds);
258-
258+
259259
// Set to 2700K (warm white)
260260
mireds = 1000000 / 2700; // = 370 mireds
261261
light.setLightColorTemperature(mireds);

libraries/Zigbee/keywords.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,4 +346,4 @@ ZIGBEE_COLOR_CAPABILITY_X_Y LITERAL1
346346
ZIGBEE_COLOR_CAPABILITY_COLOR_TEMP LITERAL1
347347
ZIGBEE_COLOR_MODE_HUE_SATURATION LITERAL1
348348
ZIGBEE_COLOR_MODE_CURRENT_X_Y LITERAL1
349-
ZIGBEE_COLOR_MODE_TEMPERATURE LITERAL1
349+
ZIGBEE_COLOR_MODE_TEMPERATURE LITERAL1

libraries/Zigbee/src/ep/ZigbeeColorDimmableLight.cpp

Lines changed: 30 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -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() {
252252
void 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

373365
bool 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

492485
bool 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
}

libraries/Zigbee/src/ep/ZigbeeColorDimmableLight.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@
6666

6767
// Color capabilities bit flags (matching ZCL spec) - can be combined with bitwise OR
6868
static constexpr uint16_t ZIGBEE_COLOR_CAPABILITY_HUE_SATURATION = (1 << 0); // Bit 0: Hue/saturation supported
69-
static constexpr uint16_t ZIGBEE_COLOR_CAPABILITY_ENHANCED_HUE = (1 << 1); // Bit 1: Enhanced hue supported
70-
static constexpr uint16_t ZIGBEE_COLOR_CAPABILITY_COLOR_LOOP = (1 << 2); // Bit 2: Color loop supported
71-
static constexpr uint16_t ZIGBEE_COLOR_CAPABILITY_X_Y = (1 << 3); // Bit 3: X/Y supported
72-
static constexpr uint16_t ZIGBEE_COLOR_CAPABILITY_COLOR_TEMP = (1 << 4); // Bit 4: Color temperature supported
69+
static constexpr uint16_t ZIGBEE_COLOR_CAPABILITY_ENHANCED_HUE = (1 << 1); // Bit 1: Enhanced hue supported
70+
static constexpr uint16_t ZIGBEE_COLOR_CAPABILITY_COLOR_LOOP = (1 << 2); // Bit 2: Color loop supported
71+
static constexpr uint16_t ZIGBEE_COLOR_CAPABILITY_X_Y = (1 << 3); // Bit 3: X/Y supported
72+
static constexpr uint16_t ZIGBEE_COLOR_CAPABILITY_COLOR_TEMP = (1 << 4); // Bit 4: Color temperature supported
7373

7474
// Color mode enum values (matching ZCL spec)
7575
enum ZigbeeColorMode {

0 commit comments

Comments
 (0)