Add debugging for network scan (#1559)

* Add debugging for network scan

* Fix eslint warning
This commit is contained in:
clockbrain
2019-05-24 02:53:47 +10:00
committed by Koen Kanters
parent af09624cff
commit c4e9ea208a
+6 -1
View File
@@ -305,6 +305,7 @@ class Zigbee {
};
const processResponse = function(parent, shepherd) {
logger.debug(`Scanning device: '${parent}'`);
return function(data) {
const linkSet = [];
return new Promise((resolve) => {
@@ -315,21 +316,25 @@ class Zigbee {
linkSet.push(devinfo);
});
resolve(linkSet);
logger.debug(`Processed device: '${parent}', linkSet: %j`, linkSet);
});
};
};
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));
}, 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) => {
const linkMap = [].concat(...linkSets);
logger.info('Network scan completed');
logger.debug(`Link map: %j`, linkMap);
callback(linkMap);
})
.catch(function(result) {
logger.info('Network scan failed');
logger.info(`Network scan failed: '${result}'`);
callback([]);
});
}