Network map fixes (#1590)

* Remove device status from network scan topology

* Random start for each lqi scan then sort resultant link map

* Fix log statement order

* Sort network map links by composite key

* Fix typo in link sorting

* Fix eslint formatting
This commit is contained in:
clockbrain
2019-06-02 10:05:44 +02:00
committed by Koen Kanters
parent 08e55e469f
commit 4497214588
+8 -6
View File
@@ -304,7 +304,7 @@ class Zigbee {
}));
};
const processResponse = function(parent, shepherd) {
const processResponse = function(parent) {
logger.debug(`Scanning device: '${parent}'`);
return function(data) {
const linkSet = [];
@@ -312,9 +312,7 @@ class Zigbee {
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);
});
}
@@ -326,8 +324,9 @@ 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))
// Delay the start of each device scan by a random time to avoid network congestion
return Promise.delay(Math.random()*3000, this.shepherd.lqi(dev.ieeeAddr))
.then(processResponse(dev.ieeeAddr))
.catch(() => {
return new Promise((resolve) => []);
});
@@ -335,7 +334,10 @@ class Zigbee {
logger.debug('All network map promises created');
// 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);
// Assemble the individual scan results then sort by ieeeAddr to generate consistent maps
const linkMap = [].concat(...linkSets)
.sort((a, b) => ((a.parent + '|' + a.ieeeAddr) > (b.parent + '|' + b.ieeeAddr)) ? 1
: (((b.parent + '|' + b.ieeeAddr) > (a.parent + '|' + a.ieeeAddr)) ? -1 : 0));
logger.info('Network scan completed');
logger.debug(`Link map: %j`, linkMap);
callback(linkMap);