Skip to content

Commit

Permalink
Fix for hobbyquaker#160 and better serial error handling
Browse files Browse the repository at this point in the history
We just check for the existence of the supportsLED method and only then run the code which used to work in older zigbee-herdsman versions.
In case of problems in connect we now properly stop the zigbee adapter before trying to restart it. This was a problem uncovered by hobbyquaker#160 but not the root cause (this was the call to a no-longer-existing method of zigbee-herdsman.
  • Loading branch information
hogthrob authored Nov 28, 2021
1 parent c1118eb commit e560808
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions nodes/shepherd.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,18 +619,21 @@ module.exports = function (RED) {
this.proxy.emit('ready');
this.status = 'connected';
this.proxy.emit('nodeStatus', {fill: 'green', shape: 'dot', text: 'connected'});
this.herdsman.supportsLED().then(supportsLED => {
if (supportsLED === true) {
this.herdsman.setLED(this.led === 'enabled').then(() => {
this.debug(`setLED successfully set ${this.led}`);
}).catch(error => {
this.error(`setLED failed to set ${this.led} ${error.message}`);
});
} else if (this.led === 'enabled') {
this.error('Setting LED not supported on this adapter. To avoid this message at startup, set CC2531 LED to \'disabled\' in controller node');
}
});


if (this.herdsman.supportsLED !== undefined)
{
this.herdsman.supportsLED().then(supportsLED => {
if (supportsLED === true) {
this.herdsman.setLED(this.led === 'enabled').then(() => {
this.debug(`setLED successfully set ${this.led}`);
}).catch(error => {
this.error(`setLED failed to set ${this.led} ${error.message}`);
});
} else if (this.led === 'enabled') {
this.error('Setting LED not supported on this adapter. To avoid this message at startup, set CC2531 LED to \'disabled\' in controller node');
}
});
}
this.checkOverdueInterval = setInterval(() => {
this.checkOverdue();
}, 60 * 1000);
Expand All @@ -653,9 +656,12 @@ module.exports = function (RED) {
this.status = error.message;
this.proxy.emit('nodeStatus', {fill: 'red', shape: 'ring', text: error.message + ', retrying'});
this.error(error.message);
setTimeout(() => {
this.connect();
}, 10000);

this.herdsman.finally().then( () => {
setTimeout(() => {
this.connect();
}, 10000);
});
}).finally(() => {
this.connecting = false;
});
Expand Down

0 comments on commit e560808

Please sign in to comment.