diff --git a/lib/controller.js b/lib/controller.js index f60aedf7..fc35e2aa 100644 --- a/lib/controller.js +++ b/lib/controller.js @@ -318,7 +318,7 @@ class Controller { logger.error(`Cannot handle '${topic}' because deviceID of '${message.toString()}' cannot be found`); return; } - this.zigbee.removedevice(deviceID) + this.zigbee.removedevice(deviceID); } else { logger.error(`Cannot handle MQTT config option '${option}' with Payload is null - we need the friendly_name to proceed`); return; diff --git a/lib/zigbee.js b/lib/zigbee.js index 544c3db0..925fcf43 100644 --- a/lib/zigbee.js +++ b/lib/zigbee.js @@ -109,19 +109,26 @@ class Zigbee { } removedevice(deviceID) { - if (deviceID) { - logger.info(`Found Device with ID ${deviceID}`); - this.shepherd.remove('deviceID', function (err) { - if (err) { - console.log(`Failed to removed ${deviceID}`); - } else { - console.log(`Successfully removed ${deviceID}`); - } - }); + this.shepherd.remove('deviceID', (err) => { + if (err) { + logger.warn(`Failed to remove ${deviceID}`); + this.forceRemove(deviceID); } else { - logger.error('removedevice function need deviceID to proceed'); - return; + logger.info(`Successfully removed ${deviceID}`); } + }); + } + + forceRemove(deviceID) { + const device = this.shepherd._findDevByAddr(deviceID); + // force + return this.shepherd._unregisterDev(device, (err) => { + if (err) { + logger.warn(`Failed to force remove ${deviceID}`); + } else { + logger.info(`Successfully removed by force ${deviceID}`); + } + }); } ping(deviceID) {