Refactor addCoordinatorToGroup.

This commit is contained in:
Koen Kanters
2019-02-13 20:43:22 +01:00
parent 21a782d2c6
commit 9faeb53ddb
2 changed files with 28 additions and 29 deletions
+22 -15
View File
@@ -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);