Skip to content

Commit 4dff4ec

Browse files
ci(pre-commit): Apply automatic fixes
1 parent 94e00fe commit 4dff4ec

File tree

8 files changed

+97
-95
lines changed

8 files changed

+97
-95
lines changed

libraries/Zigbee/examples/Zigbee_On_Off_MultiSwitch/Zigbee_On_Off_MultiSwitch.ino

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,14 @@
2828
* Created by Jan Procházka (https://github.com/P-R-O-C-H-Y/)
2929
*/
3030

31-
3231
#ifndef ZIGBEE_MODE_ZCZR
3332
#error "Zigbee coordinator mode is not selected in Tools->Zigbee mode"
3433
#endif
3534

3635
#include "Zigbee.h"
3736
#include <Preferences.h>
3837

39-
#define ZIGBEE_ROLE ZIGBEE_ROUTER // ZIGBEE_ROUTER for HomeAssistant integration, ZIGBEE_COORDINATOR for running own network
38+
#define ZIGBEE_ROLE ZIGBEE_ROUTER // ZIGBEE_ROUTER for HomeAssistant integration, ZIGBEE_COORDINATOR for running own network
4039

4140
/* Zigbee switch configuration */
4241
#define SWITCH_ENDPOINT_NUMBER 1
@@ -45,7 +44,7 @@ uint8_t button = BOOT_PIN;
4544

4645
ZigbeeSwitch zbSwitch = ZigbeeSwitch(SWITCH_ENDPOINT_NUMBER);
4746

48-
int buttonState;
47+
int buttonState;
4948
int lastButtonState = LOW;
5049
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
5150
unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers
@@ -88,12 +87,12 @@ void setup() {
8887
zbSwitch.setManufacturerAndModel("Espressif", "ZBMultiSwitch");
8988

9089
// Set binding settings depending on the role
91-
if(ZIGBEE_ROLE == ZIGBEE_COORDINATOR) {
92-
zbSwitch.allowMultipleBinding(true); // To allow binding multiple lights to the switch
90+
if (ZIGBEE_ROLE == ZIGBEE_COORDINATOR) {
91+
zbSwitch.allowMultipleBinding(true); // To allow binding multiple lights to the switch
9392
} else {
94-
zbSwitch.setManualBinding(true); //Set manual binding to true, so binding is done on Home Assistant side
93+
zbSwitch.setManualBinding(true); //Set manual binding to true, so binding is done on Home Assistant side
9594
}
96-
95+
9796
// Add endpoint to Zigbee Core
9897
Serial.println("Adding ZigbeeSwitch endpoint to Zigbee Core");
9998
Zigbee.addEndpoint(&zbSwitch);
@@ -133,7 +132,7 @@ void loop() {
133132
String command = Serial.readString();
134133
Serial.println("Command: " + command);
135134

136-
if(command == "config") {
135+
if (command == "config") {
137136
//wait for light number, endpoint and ieee address
138137
Serial.println("Enter light number (1-3):");
139138
while (!Serial.available()) {
@@ -147,7 +146,7 @@ void loop() {
147146
int endpoint = Serial.parseInt();
148147
Serial.println("Enter ieee address:");
149148
while (!Serial.available()) {
150-
delay(100);
149+
delay(100);
151150
}
152151
String ieee_address = Serial.readStringUntil('\n');
153152
ieee_address.trim();
@@ -157,19 +156,19 @@ void loop() {
157156
bool valid = true;
158157

159158
// Check if the string has the correct format (8 hex pairs with colons)
160-
if (ieee_address.length() != 23) { // 8 pairs * 2 + 7 colons
159+
if (ieee_address.length() != 23) { // 8 pairs * 2 + 7 colons
161160
Serial.println("Invalid IEEE address format. Expected format: 00:00:00:00:00:00:00:00");
162161
valid = false;
163162
} else {
164163
for (int i = 0; i < ieee_address.length() && index < 8 && valid; i += 3) {
165164
// Check for colon at expected positions
166-
if (i > 0 && ieee_address.charAt(i-1) != ':') {
165+
if (i > 0 && ieee_address.charAt(i - 1) != ':') {
167166
valid = false;
168167
break;
169168
}
170169
// Convert two hex characters to a byte
171-
char hex[3] = {ieee_address.charAt(i), ieee_address.charAt(i+1), '\0'};
172-
char* endptr;
170+
char hex[3] = {ieee_address.charAt(i), ieee_address.charAt(i + 1), '\0'};
171+
char *endptr;
173172
long value = strtol(hex, &endptr, 16);
174173
if (*endptr != '\0' || value < 0 || value > 255) {
175174
valid = false;
@@ -185,15 +184,15 @@ void loop() {
185184
return;
186185
}
187186
//set the light parameters
188-
if(light_number == 1) {
187+
if (light_number == 1) {
189188
light_1.endpoint = endpoint;
190189
memcpy(light_1.ieee_addr, ieee_address_array, 8);
191190
storeLightParams(&light_1, 1);
192-
} else if(light_number == 2) {
191+
} else if (light_number == 2) {
193192
light_2.endpoint = endpoint;
194193
memcpy(light_2.ieee_addr, ieee_address_array, 8);
195194
storeLightParams(&light_2, 2);
196-
} else if(light_number == 3) {
195+
} else if (light_number == 3) {
197196
light_3.endpoint = endpoint;
198197
memcpy(light_3.ieee_addr, ieee_address_array, 8);
199198
storeLightParams(&light_3, 3);
@@ -207,15 +206,15 @@ void loop() {
207206
}
208207
int light_number = Serial.parseInt();
209208
uint8_t ieee_address_empty[8] = {0, 0, 0, 0, 0, 0, 0, 0};
210-
if(light_number == 1) {
209+
if (light_number == 1) {
211210
light_1.endpoint = 0;
212211
memcpy(light_1.ieee_addr, ieee_address_empty, 8);
213212
storeLightParams(&light_1, 1);
214-
} else if(light_number == 2) {
213+
} else if (light_number == 2) {
215214
light_2.endpoint = 0;
216215
memcpy(light_2.ieee_addr, ieee_address_empty, 8);
217216
storeLightParams(&light_2, 2);
218-
} else if(light_number == 3) {
217+
} else if (light_number == 3) {
219218
light_3.endpoint = 0;
220219
memcpy(light_3.ieee_addr, ieee_address_empty, 8);
221220
storeLightParams(&light_3, 3);
@@ -263,7 +262,7 @@ void loop() {
263262
Zigbee.factoryReset();
264263
} else if (command == "open_network") {
265264
Serial.println(" --> SIG Input : Open Network");
266-
if(ZIGBEE_ROLE == ZIGBEE_COORDINATOR) {
265+
if (ZIGBEE_ROLE == ZIGBEE_COORDINATOR) {
267266
Zigbee.openNetwork(180);
268267
} else {
269268
Serial.println("Open network is only available for coordinator role");
@@ -272,4 +271,4 @@ void loop() {
272271
Serial.println("Unknown command");
273272
}
274273
}
275-
}
274+
}

libraries/Zigbee/src/ZigbeeCore.cpp

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) {
282282
} else {
283283
// Save the channel mask to NVRAM in case of reboot which may be on a different channel after a change in the network
284284
Zigbee.setNVRAMChannelMask(1 << esp_zb_get_current_channel());
285-
Zigbee._connected = true; // Coordinator is always connected
285+
Zigbee._connected = true; // Coordinator is always connected
286286
}
287287
Zigbee.searchBindings();
288288
}
@@ -374,7 +374,7 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) {
374374
log_d("Device not bound to endpoint %d and it is free to bound!", (*it)->getEndpoint());
375375
(*it)->findEndpoint(&cmd_req);
376376
log_d("Endpoint %d is searching for device", (*it)->getEndpoint());
377-
break; // Only one endpoint per device
377+
break; // Only one endpoint per device
378378
}
379379
}
380380
}
@@ -408,7 +408,7 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) {
408408
if (!found) {
409409
(*it)->findEndpoint(&cmd_req);
410410
log_d("Endpoint %d is searching for device", (*it)->getEndpoint());
411-
break; // Only one endpoint per device
411+
break; // Only one endpoint per device
412412
}
413413
}
414414
}
@@ -437,25 +437,27 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) {
437437
}
438438

439439
// APS DATA INDICATION HANDLER to catch bind/unbind requests
440-
bool zb_apsde_data_indication_handler(esp_zb_apsde_data_ind_t ind)
441-
{
440+
bool zb_apsde_data_indication_handler(esp_zb_apsde_data_ind_t ind) {
442441
if (Zigbee.getDebugMode()) {
443442
log_d("APSDE INDICATION - Received APSDE-DATA indication, status: %d", ind.status);
444-
log_d("APSDE INDICATION - dst_endpoint: %d, src_endpoint: %d, dst_addr_mode: %d, src_addr_mode: %d, cluster_id: 0x%04x, asdu_length: %d", ind.dst_endpoint, ind.src_endpoint, ind.dst_addr_mode, ind.src_addr_mode, ind.cluster_id, ind.asdu_length);
445-
log_d("APSDE INDICATION - dst_short_addr: 0x%04x, src_short_addr: 0x%04x, profile_id: 0x%04x, security_status: %d, lqi: %d, rx_time: %d", ind.dst_short_addr, ind.src_short_addr, ind.profile_id, ind.security_status, ind.lqi, ind.rx_time);
443+
log_d(
444+
"APSDE INDICATION - dst_endpoint: %d, src_endpoint: %d, dst_addr_mode: %d, src_addr_mode: %d, cluster_id: 0x%04x, asdu_length: %d", ind.dst_endpoint,
445+
ind.src_endpoint, ind.dst_addr_mode, ind.src_addr_mode, ind.cluster_id, ind.asdu_length
446+
);
447+
log_d(
448+
"APSDE INDICATION - dst_short_addr: 0x%04x, src_short_addr: 0x%04x, profile_id: 0x%04x, security_status: %d, lqi: %d, rx_time: %d", ind.dst_short_addr,
449+
ind.src_short_addr, ind.profile_id, ind.security_status, ind.lqi, ind.rx_time
450+
);
446451
}
447-
if (ind.status == 0x00)
448-
{
449-
// Catch bind/unbind requests to update the bound devices list
450-
if(ind.cluster_id == 0x21 || ind.cluster_id == 0x22){
451-
Zigbee.searchBindings();
452-
}
452+
if (ind.status == 0x00) {
453+
// Catch bind/unbind requests to update the bound devices list
454+
if (ind.cluster_id == 0x21 || ind.cluster_id == 0x22) {
455+
Zigbee.searchBindings();
453456
}
454-
else
455-
{
456-
log_e("APSDE INDICATION - Invalid status of APSDE-DATA indication, error code: %d", ind.status);
457-
}
458-
return false; //False to let the stack process the message as usual
457+
} else {
458+
log_e("APSDE INDICATION - Invalid status of APSDE-DATA indication, error code: %d", ind.status);
459+
}
460+
return false; //False to let the stack process the message as usual
459461
}
460462

461463
void ZigbeeCore::factoryReset(bool restart) {
@@ -527,7 +529,7 @@ void ZigbeeCore::bindingTableCb(const esp_zb_zdo_binding_table_info_t *table_inf
527529
esp_zb_zdo_mgmt_bind_param_t *req = (esp_zb_zdo_mgmt_bind_param_t *)user_ctx;
528530
esp_zb_zdp_status_t zdo_status = (esp_zb_zdp_status_t)table_info->status;
529531
log_d("Binding table callback for address 0x%04x with status %d", req->dst_addr, zdo_status);
530-
532+
531533
if (zdo_status == ESP_ZB_ZDP_STATUS_SUCCESS) {
532534
// Print binding table log simple
533535
log_d("Binding table info: total %d, index %d, count %d", table_info->total, table_info->index, table_info->count);
@@ -549,10 +551,14 @@ void ZigbeeCore::bindingTableCb(const esp_zb_zdo_binding_table_info_t *table_inf
549551
uint16_t short_addr;
550552
esp_zb_ieee_addr_t ieee_addr;
551553
bool is_ieee;
552-
553-
bool operator<(const DeviceIdentifier& other) const {
554-
if (endpoint != other.endpoint) return endpoint < other.endpoint;
555-
if (is_ieee != other.is_ieee) return is_ieee < other.is_ieee;
554+
555+
bool operator<(const DeviceIdentifier &other) const {
556+
if (endpoint != other.endpoint) {
557+
return endpoint < other.endpoint;
558+
}
559+
if (is_ieee != other.is_ieee) {
560+
return is_ieee < other.is_ieee;
561+
}
556562
if (is_ieee) {
557563
return memcmp(ieee_addr, other.ieee_addr, sizeof(esp_zb_ieee_addr_t)) < 0;
558564
}
@@ -571,30 +577,31 @@ void ZigbeeCore::bindingTableCb(const esp_zb_zdo_binding_table_info_t *table_inf
571577
// Add current records to our collection
572578
esp_zb_zdo_binding_table_record_t *record = table_info->record;
573579
for (int i = 0; i < table_info->count; i++) {
574-
log_d("Processing record %d: src_endp %d, dst_endp %d, cluster_id 0x%04x, dst_addr_mode %d",
575-
i, record->src_endp, record->dst_endp, record->cluster_id, record->dst_addr_mode);
580+
log_d(
581+
"Processing record %d: src_endp %d, dst_endp %d, cluster_id 0x%04x, dst_addr_mode %d", i, record->src_endp, record->dst_endp, record->cluster_id,
582+
record->dst_addr_mode
583+
);
576584
all_records.push_back(*record);
577585
record = record->next;
578586
}
579587

580588
// If this is not the last chunk, request the next one
581589
if (table_info->index + table_info->count < table_info->total) {
582-
log_d("Requesting next chunk of binding table (current index: %d, count: %d, total: %d)",
583-
table_info->index, table_info->count, table_info->total);
590+
log_d("Requesting next chunk of binding table (current index: %d, count: %d, total: %d)", table_info->index, table_info->count, table_info->total);
584591
req->start_index = table_info->index + table_info->count;
585592
esp_zb_zdo_binding_table_req(req, bindingTableCb, req);
586593
} else {
587594
// This is the last chunk, process all records
588595
log_d("Processing final chunk of binding table, total records: %d", all_records.size());
589-
for (const auto& record : all_records) {
596+
for (const auto &record : all_records) {
590597

591598
DeviceIdentifier dev_id;
592599
dev_id.endpoint = record.src_endp;
593600
dev_id.is_ieee = (record.dst_addr_mode == ESP_ZB_APS_ADDR_MODE_64_ENDP_PRESENT);
594-
601+
595602
if (dev_id.is_ieee) {
596603
memcpy(dev_id.ieee_addr, record.dst_address.addr_long, sizeof(esp_zb_ieee_addr_t));
597-
dev_id.short_addr = 0xFFFF; // Invalid short address
604+
dev_id.short_addr = 0xFFFF; // Invalid short address
598605
} else {
599606
dev_id.short_addr = record.dst_address.addr_short;
600607
memset(dev_id.ieee_addr, 0, sizeof(esp_zb_ieee_addr_t));
@@ -609,15 +616,15 @@ void ZigbeeCore::bindingTableCb(const esp_zb_zdo_binding_table_info_t *table_inf
609616
log_d("Processing endpoint %d", (*it)->getEndpoint());
610617
std::list<zb_device_params_t *> bound_devices = (*it)->getBoundDevices();
611618
std::list<zb_device_params_t *> devices_to_remove;
612-
619+
613620
// First, identify devices that need to be removed
614621
for (std::list<zb_device_params_t *>::iterator dev_it = bound_devices.begin(); dev_it != bound_devices.end(); ++dev_it) {
615622
DeviceIdentifier dev_id;
616623
dev_id.endpoint = (*it)->getEndpoint();
617-
624+
618625
// Create both short and IEEE address identifiers for the device
619626
bool found = false;
620-
627+
621628
// Check if device exists with short address
622629
if ((*dev_it)->short_addr != 0xFFFF) {
623630
dev_id.is_ieee = false;
@@ -627,7 +634,7 @@ void ZigbeeCore::bindingTableCb(const esp_zb_zdo_binding_table_info_t *table_inf
627634
found = true;
628635
}
629636
}
630-
637+
631638
// Check if device exists with IEEE address
632639
if (!found) {
633640
dev_id.is_ieee = true;
@@ -637,20 +644,20 @@ void ZigbeeCore::bindingTableCb(const esp_zb_zdo_binding_table_info_t *table_inf
637644
found = true;
638645
}
639646
}
640-
647+
641648
if (!found) {
642649
devices_to_remove.push_back(*dev_it);
643650
}
644651
}
645-
652+
646653
// Remove devices that are no longer in the binding table
647654
for (std::list<zb_device_params_t *>::iterator dev_it = devices_to_remove.begin(); dev_it != devices_to_remove.end(); ++dev_it) {
648655
(*it)->removeBoundDevice(*dev_it);
649656
free(*dev_it);
650657
}
651658

652659
// Now add new devices from the binding table
653-
for (const auto& record : all_records) {
660+
for (const auto &record : all_records) {
654661
if (record.src_endp == (*it)->getEndpoint()) {
655662
log_d("Processing binding record for EP %d", record.src_endp);
656663
zb_device_params_t *device = (zb_device_params_t *)calloc(1, sizeof(zb_device_params_t));
@@ -659,7 +666,7 @@ void ZigbeeCore::bindingTableCb(const esp_zb_zdo_binding_table_info_t *table_inf
659666
continue;
660667
}
661668
device->endpoint = record.dst_endp;
662-
669+
663670
bool is_ieee = (record.dst_addr_mode == ESP_ZB_APS_ADDR_MODE_64_ENDP_PRESENT);
664671
if (is_ieee) {
665672
memcpy(device->ieee_addr, record.dst_address.addr_long, sizeof(esp_zb_ieee_addr_t));
@@ -684,20 +691,16 @@ void ZigbeeCore::bindingTableCb(const esp_zb_zdo_binding_table_info_t *table_inf
684691
}
685692
}
686693
}
687-
694+
688695
if (!device_exists) {
689696
(*it)->addBoundDevice(device);
690697
log_d(
691-
"Device bound to EP %d -> device endpoint: %d, %s: %s",
692-
record.src_endp, device->endpoint,
693-
is_ieee ? "ieee addr" : "short addr",
694-
is_ieee ?
695-
formatIEEEAddress(device->ieee_addr) :
696-
formatShortAddress(device->short_addr)
698+
"Device bound to EP %d -> device endpoint: %d, %s: %s", record.src_endp, device->endpoint, is_ieee ? "ieee addr" : "short addr",
699+
is_ieee ? formatIEEEAddress(device->ieee_addr) : formatShortAddress(device->short_addr)
697700
);
698701
} else {
699702
log_d("Device already exists, freeing allocated memory");
700-
free(device); // Free the device if it already exists
703+
free(device); // Free the device if it already exists
701704
}
702705
}
703706
}

libraries/Zigbee/src/ZigbeeCore.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,13 @@ class ZigbeeCore {
181181
friend bool zb_apsde_data_indication_handler(esp_zb_apsde_data_ind_t ind);
182182

183183
// Helper functions for formatting addresses
184-
static inline const char* formatIEEEAddress(const esp_zb_ieee_addr_t addr) {
184+
static inline const char *formatIEEEAddress(const esp_zb_ieee_addr_t addr) {
185185
static char buf[24];
186-
snprintf(buf, sizeof(buf), "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",
187-
addr[7], addr[6], addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
186+
snprintf(buf, sizeof(buf), "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X", addr[7], addr[6], addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
188187
return buf;
189188
}
190189

191-
static inline const char* formatShortAddress(uint16_t addr) {
190+
static inline const char *formatShortAddress(uint16_t addr) {
192191
static char buf[7];
193192
snprintf(buf, sizeof(buf), "0x%04X", addr);
194193
return buf;

0 commit comments

Comments
 (0)