Simpler network map scan (#1543)

* Initial iterative rewrite of network scan

* Remove unused linkKey

* Restore original log message

* Cleaner array flattening

* Fix various travis warnings
This commit is contained in:
clockbrain
2019-05-19 19:33:30 +02:00
committed by Koen Kanters
parent 6b7546547d
commit 31d21546b9
+31 -3
View File
@@ -267,16 +267,44 @@ class Zigbee {
return this.shepherd.find(device.ieeeAddr, 1);
}
getScanable() {
return this.getDevices().filter((d) => d.type != 'EndDevice');
}
getGroup(ID) {
return this.shepherd.getGroup(ID);
}
networkScan(callback) {
logger.info('Starting network scan...');
this.shepherd.lqiScan().then((result) => {
const processResponse = function(parent, shepherd) {
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);
});
resolve(linkSet);
});
};
};
const allScans = this.getScanable().map((dev) => {
return this.shepherd.lqi(dev.ieeeAddr).then(processResponse(dev.ieeeAddr, this.shepherd));
}, this);
Promise.all(allScans).then((linkSets) => {
const linkMap = [].concat(...linkSets);
logger.info('Network scan completed');
callback(result);
});
callback(linkMap);
})
.catch(function() {
logger.info('Network scan failed');
callback([]);
});
}
getEndpoint(ieeeAddr, ep) {