Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ddf8c42

Browse files
ci(pre-commit): Apply automatic fixes
1 parent ae274ee commit ddf8c42

File tree

3 files changed

+40
-76
lines changed

3 files changed

+40
-76
lines changed

‎libraries/Zigbee/examples/Zigbee_Dimmable_Light/Zigbee_Dimmable_Light.ino

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,19 @@ uint8_t button = BOOT_PIN;
4141
ZigbeeDimmableLight zbDimmableLight = ZigbeeDimmableLight(ZIGBEE_LIGHT_ENDPOINT);
4242

4343
/********************* RGB LED functions **************************/
44-
void setLight(bool state, uint8_t level)
45-
{
46-
if (!state)
47-
{
44+
void setLight(bool state, uint8_t level) {
45+
if (!state) {
4846
rgbLedWrite(led, 0, 0, 0);
4947
return;
5048
}
5149
rgbLedWrite(led, level, level, level);
5250
}
5351

5452
// Create a task on identify call to handle the identify function
55-
void identify(uint16_t time)
56-
{
53+
void identify(uint16_t time) {
5754
static uint8_t blink = 1;
5855
log_d("Identify called for %d seconds", time);
59-
if (time == 0)
60-
{
56+
if (time == 0) {
6157
// If identify time is 0, stop blinking and restore light as it was used for identify
6258
zbDimmableLight.restoreLight();
6359
return;
@@ -67,8 +63,7 @@ void identify(uint16_t time)
6763
}
6864

6965
/********************* Arduino functions **************************/
70-
void setup()
71-
{
66+
void setup() {
7267
Serial.begin(115200);
7368

7469
// Init RMT and leave light OFF
@@ -91,34 +86,28 @@ void setup()
9186
Zigbee.addEndpoint(&zbDimmableLight);
9287

9388
// When all EPs are registered, start Zigbee in End Device mode
94-
if (!Zigbee.begin())
95-
{
89+
if (!Zigbee.begin()) {
9690
Serial.println("Zigbee failed to start!");
9791
Serial.println("Rebooting...");
9892
ESP.restart();
9993
}
10094
Serial.println("Connecting to network");
101-
while (!Zigbee.connected())
102-
{
95+
while (!Zigbee.connected()) {
10396
Serial.print(".");
10497
delay(100);
10598
}
10699
Serial.println();
107100
}
108101

109-
void loop()
110-
{
102+
void loop() {
111103
// Checking button for factory reset
112-
if (digitalRead(button) == LOW)
113-
{ // Push button pressed
104+
if (digitalRead(button) == LOW) { // Push button pressed
114105
// Key debounce handling
115106
delay(100);
116107
int startTime = millis();
117-
while (digitalRead(button) == LOW)
118-
{
108+
while (digitalRead(button) == LOW) {
119109
delay(50);
120-
if ((millis() - startTime) > 3000)
121-
{
110+
if ((millis() - startTime) > 3000) {
122111
// If key pressed for more than 3secs, factory reset Zigbee and reboot
123112
Serial.println("Resetting Zigbee to factory and rebooting in 1s.");
124113
delay(1000);

‎libraries/Zigbee/src/ep/ZigbeeDimmableLight.cpp

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
#include "esp_zigbee_cluster.h"
66

7-
ZigbeeDimmableLight::ZigbeeDimmableLight(uint8_t endpoint) : ZigbeeEP(endpoint)
8-
{
7+
ZigbeeDimmableLight::ZigbeeDimmableLight(uint8_t endpoint) : ZigbeeEP(endpoint) {
98
_device_id = ESP_ZB_HA_DIMMABLE_LIGHT_DEVICE_ID;
109

1110
zigbee_dimmable_light_cfg_t light_cfg = ZIGBEE_DEFAULT_DIMMABLE_LIGHT_CONFIG();
@@ -19,58 +18,41 @@ ZigbeeDimmableLight::ZigbeeDimmableLight(uint8_t endpoint) : ZigbeeEP(endpoint)
1918
}
2019

2120
// set attribute method -> method overridden in child class
22-
void ZigbeeDimmableLight::zbAttributeSet(const esp_zb_zcl_set_attr_value_message_t *message)
23-
{
21+
void ZigbeeDimmableLight::zbAttributeSet(const esp_zb_zcl_set_attr_value_message_t *message) {
2422
// check the data and call right method
25-
if (message->info.cluster == ESP_ZB_ZCL_CLUSTER_ID_ON_OFF)
26-
{
27-
if (message->attribute.id == ESP_ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID && message->attribute.data.type == ESP_ZB_ZCL_ATTR_TYPE_BOOL)
28-
{
29-
if (_current_state != *(bool *)message->attribute.data.value)
30-
{
23+
if (message->info.cluster == ESP_ZB_ZCL_CLUSTER_ID_ON_OFF) {
24+
if (message->attribute.id == ESP_ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID && message->attribute.data.type == ESP_ZB_ZCL_ATTR_TYPE_BOOL) {
25+
if (_current_state != *(bool *)message->attribute.data.value) {
3126
_current_state = *(bool *)message->attribute.data.value;
3227
lightChanged();
3328
}
3429
return;
35-
}
36-
else
37-
{
30+
} else {
3831
log_w("Received message ignored. Attribute ID: %d not supported for On/Off Light", message->attribute.id);
3932
}
40-
}
41-
else if (message->info.cluster == ESP_ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL)
42-
{
43-
if (message->attribute.id == ESP_ZB_ZCL_ATTR_LEVEL_CONTROL_CURRENT_LEVEL_ID && message->attribute.data.type == ESP_ZB_ZCL_ATTR_TYPE_U8)
44-
{
45-
if (_current_level != *(uint8_t *)message->attribute.data.value)
46-
{
33+
} else if (message->info.cluster == ESP_ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL) {
34+
if (message->attribute.id == ESP_ZB_ZCL_ATTR_LEVEL_CONTROL_CURRENT_LEVEL_ID && message->attribute.data.type == ESP_ZB_ZCL_ATTR_TYPE_U8) {
35+
if (_current_level != *(uint8_t *)message->attribute.data.value) {
4736
_current_level = *(uint8_t *)message->attribute.data.value;
4837
lightChanged();
4938
}
5039
return;
51-
}
52-
else
53-
{
40+
} else {
5441
log_w("Received message ignored. Attribute ID: %d not supported for Level Control", message->attribute.id);
5542
// TODO: implement more attributes -> includes/zcl/esp_zigbee_zcl_level.h
5643
}
57-
}
58-
else
59-
{
44+
} else {
6045
log_w("Received message ignored. Cluster ID: %d not supported for dimmable Light", message->info.cluster);
6146
}
6247
}
6348

64-
void ZigbeeDimmableLight::lightChanged()
65-
{
66-
if (_on_light_change)
67-
{
49+
void ZigbeeDimmableLight::lightChanged() {
50+
if (_on_light_change) {
6851
_on_light_change(_current_state, _current_level);
6952
}
7053
}
7154

72-
void ZigbeeDimmableLight::setLight(bool state, uint8_t level)
73-
{
55+
void ZigbeeDimmableLight::setLight(bool state, uint8_t level) {
7456
// Update all attributes
7557
_current_state = state;
7658
_current_level = level;
@@ -81,25 +63,24 @@ void ZigbeeDimmableLight::setLight(bool state, uint8_t level)
8163
esp_zb_lock_acquire(portMAX_DELAY);
8264
// set on/off state
8365
esp_zb_zcl_set_attribute_val(
84-
_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);
66+
_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
67+
);
8568
// set level
8669
esp_zb_zcl_set_attribute_val(
87-
_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);
70+
_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
71+
);
8872
esp_zb_lock_release();
8973
}
9074

91-
void ZigbeeDimmableLight::setLightState(bool state)
92-
{
75+
void ZigbeeDimmableLight::setLightState(bool state) {
9376
setLight(state, _current_level);
9477
}
9578

96-
void ZigbeeDimmableLight::setLightLevel(uint8_t level)
97-
{
79+
void ZigbeeDimmableLight::setLightLevel(uint8_t level) {
9880
setLight(_current_state, level);
9981
}
10082

101-
esp_zb_cluster_list_t *ZigbeeDimmableLight::esp_zb_dimmable_light_clusters_create(zigbee_dimmable_light_cfg_t *light_cfg)
102-
{
83+
esp_zb_cluster_list_t *ZigbeeDimmableLight::esp_zb_dimmable_light_clusters_create(zigbee_dimmable_light_cfg_t *light_cfg) {
10384
esp_zb_attribute_list_t *esp_zb_basic_cluster = esp_zb_basic_cluster_create(&light_cfg->basic_cfg);
10485
esp_zb_attribute_list_t *esp_zb_identify_cluster = esp_zb_identify_cluster_create(&light_cfg->identify_cfg);
10586
esp_zb_attribute_list_t *esp_zb_groups_cluster = esp_zb_groups_cluster_create(&light_cfg->groups_cfg);
@@ -119,4 +100,4 @@ esp_zb_cluster_list_t *ZigbeeDimmableLight::esp_zb_dimmable_light_clusters_creat
119100
return esp_zb_cluster_list;
120101
}
121102

122-
#endif // SOC_IEEE802154_SUPPORTED
103+
#endif // SOC_IEEE802154_SUPPORTED

‎libraries/Zigbee/src/ep/ZigbeeDimmableLight.h

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
*
1616
*
1717
*/
18-
typedef struct zigbee_dimmable_light_cfg_s
19-
{
18+
typedef struct zigbee_dimmable_light_cfg_s {
2019
esp_zb_basic_cluster_cfg_t basic_cfg; /*!< Basic cluster configuration, @ref esp_zb_basic_cluster_cfg_s */
2120
esp_zb_identify_cluster_cfg_t identify_cfg; /*!< Identify cluster configuration, @ref esp_zb_identify_cluster_cfg_s */
2221
esp_zb_groups_cluster_cfg_t groups_cfg; /*!< Groups cluster configuration, @ref esp_zb_groups_cluster_cfg_s */
@@ -65,31 +64,26 @@ typedef struct zigbee_dimmable_light_cfg_s
6564
}
6665
// clang-format on
6766

68-
class ZigbeeDimmableLight : public ZigbeeEP
69-
{
67+
class ZigbeeDimmableLight : public ZigbeeEP {
7068
public:
7169
ZigbeeDimmableLight(uint8_t endpoint);
7270
~ZigbeeDimmableLight();
7371

74-
void onLightChange(void (*callback)(bool, uint8_t))
75-
{
72+
void onLightChange(void (*callback)(bool, uint8_t)) {
7673
_on_light_change = callback;
7774
}
78-
void restoreLight()
79-
{
75+
void restoreLight() {
8076
lightChanged();
8177
}
8278

8379
void setLightState(bool state);
8480
void setLightLevel(uint8_t level);
8581
void setLight(bool state, uint8_t level);
8682

87-
bool getLightState()
88-
{
83+
bool getLightState() {
8984
return _current_state;
9085
}
91-
uint8_t getLightLevel()
92-
{
86+
uint8_t getLightLevel() {
9387
return _current_level;
9488
}
9589

@@ -116,4 +110,4 @@ class ZigbeeDimmableLight : public ZigbeeEP
116110
uint8_t _current_level;
117111
};
118112

119-
#endif // SOC_IEEE802154_SUPPORTED
113+
#endif // SOC_IEEE802154_SUPPORTED

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /