This commit is contained in:
Koen Kanters 2019-05-07 21:00:17 +02:00
parent 68d2d0a73d
commit ba1eca82eb

View File

@ -45,6 +45,7 @@ class Zigbee {
this.onMessage = this.onMessage.bind(this);
this.onError = this.onError.bind(this);
this.messageHandler = null;
this.permitJoinTimer = null;
this.queue = new ZigbeeQueue();
}
@ -130,6 +131,10 @@ class Zigbee {
}
stop(callback) {
if (this.permitJoinTimer) {
clearInterval(this.permitJoinTimer);
}
this.queue.stop();
// Backup coordinator
@ -176,6 +181,24 @@ class Zigbee {
logger.info('Zigbee: disabling joining new devices.');
}
// In zigbee 3.0 a network automatically closes after 254 seconds.
// As a workaround, we enable joining again.
if (this.permitJoinTimer) {
clearInterval(this.permitJoinTimer);
}
if (permit) {
this.permitJoinTimer = setInterval(() => {
this.shepherd.permitJoin(255, (error) => {
if (error) {
logger.error('Failed to reenable joining');
} else {
logger.info('Succesfully reenabled joining');
}
});
}, utils.secondsToMilliseconds(200));
}
this.shepherd.permitJoin(permit ? 255 : 0, (error) => {
if (error) {
logger.info(error);