mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-08-28 23:00:55 +00:00
Refactor addCoordinatorToGroup.
This commit is contained in:
+22
-15
@@ -119,21 +119,7 @@ class Zigbee {
|
||||
}
|
||||
|
||||
// Add the coordinator to group 99
|
||||
this.shepherd.controller.request('ZDO', 'extFindGroup', {groupid: 99, endpoint: 1}, (err) => {
|
||||
// Error means that the coordinator is not in the group yet.
|
||||
if (err) {
|
||||
const payload = {groupid: 99, endpoint: 1, namelen: 0, groupname: ''};
|
||||
this.shepherd.controller.request('ZDO', 'extAddGroup', payload, (err) => {
|
||||
if (err) {
|
||||
logger.info('Successfully added coordinator to group 99');
|
||||
} else {
|
||||
logger.error('Failed to add coordinator to group 99');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
logger.debug('Coordinator is already in group 99');
|
||||
}
|
||||
});
|
||||
this.addCoordinatorToGroup(99);
|
||||
|
||||
// Wait some time before we start the queue, many calls skip this queue which hangs the stick
|
||||
setTimeout(() => {
|
||||
@@ -144,6 +130,27 @@ class Zigbee {
|
||||
logger.info('zigbee-shepherd ready');
|
||||
}
|
||||
|
||||
addCoordinatorToGroup(groupID, callback=() => {}) {
|
||||
this.shepherd.controller.request('ZDO', 'extFindGroup', {groupid: groupID, endpoint: 1}, (err) => {
|
||||
// Error means that the coordinator is not in the group yet.
|
||||
if (err) {
|
||||
const payload = {groupid: groupID, endpoint: 1, namelen: 0, groupname: ''};
|
||||
this.shepherd.controller.request('ZDO', 'extAddGroup', payload, (err) => {
|
||||
if (err) {
|
||||
logger.info(`Successfully added coordinator to group '${groupID}'`);
|
||||
callback(false);
|
||||
} else {
|
||||
logger.error(`Failed to add coordinator to group '${groupID}'`);
|
||||
callback(true);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
logger.debug(`Coordinator is already in group '${groupID}'`);
|
||||
callback(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onError(message) {
|
||||
// This event may appear if zigbee-shepherd cannot decode bad packets (invalid checksum).
|
||||
logger.error(message);
|
||||
|
||||
Reference in New Issue
Block a user