Network map error handling (#1565)

* Catch errors from failing network scans

* Tidier code for process result

* Fix eslint format errors
This commit is contained in:
clockbrain 2019-05-25 02:21:53 +10:00 committed by Koen Kanters
parent c4e9ea208a
commit 4b14222bda

View File

@ -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);