diff --git a/lib/zigbee.js b/lib/zigbee.js index dd067efb..1713e5e2 100644 --- a/lib/zigbee.js +++ b/lib/zigbee.js @@ -309,12 +309,15 @@ class Zigbee { return function(data) { const linkSet = []; return new Promise((resolve) => { - data.forEach(function(devinfo) { - const childDev = shepherd._findDevByAddr(devinfo.ieeeAddr); - devinfo.parent = parent; - devinfo.status = childDev ? childDev.status : 'offline'; - linkSet.push(devinfo); - }); + logger.debug(`Processing scan for: '${parent}'`); + if (data) { + data.forEach(function(devinfo) { + const childDev = shepherd._findDevByAddr(devinfo.ieeeAddr); + devinfo.parent = parent; + devinfo.status = childDev ? childDev.status : 'offline'; + linkSet.push(devinfo); + }); + } resolve(linkSet); logger.debug(`Processed device: '${parent}', linkSet: %j`, linkSet); }); @@ -323,11 +326,15 @@ class Zigbee { const allScans = this.getScanable().map((dev) => { logger.debug(`Preparing asynch network scan for '${dev.ieeeAddr}'`); - return this.shepherd.lqi(dev.ieeeAddr).then(processResponse(dev.ieeeAddr, this.shepherd)); + return this.shepherd.lqi(dev.ieeeAddr) + .then(processResponse(dev.ieeeAddr, this.shepherd)) + .catch(() => { + return new Promise((resolve) => []); + }); }, this); logger.debug('All network map promises created'); - // Collect all lqi scans but timeout after 2 seconds if any fail - Promise.raceAll(allScans, 2000, []).then((linkSets) => { + // Collect all lqi scan results but timeout after specified miliseconds if any haven't completed + Promise.raceAll(allScans, 8000, []).then((linkSets) => { const linkMap = [].concat(...linkSets); logger.info('Network scan completed'); logger.debug(`Link map: %j`, linkMap);