mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-08-23 11:09:52 +00:00
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:
+31
-3
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user