Refactor report to new queue mechanism.

This commit is contained in:
Koen Kanters
2019-02-23 15:39:24 +01:00
parent 09f26a104c
commit 7893f9256f
+26 -13
View File
@@ -307,9 +307,10 @@ class Zigbee {
});
}
/* setup reporting.
* attributes is an array of attribute objects.
* each attribute object contains the following properties:
/*
* Setup reporting.
* Attributes is an array of attribute objects.
* each attribute object should contain the following properties:
* attr the attribute name,
* min the minimal time between reports in seconds,
* max the maximum time between reports in seconds,
@@ -330,26 +331,38 @@ class Zigbee {
repChange: attribute.change,
});
}
const log=`for ${ep.device.ieeeAddr} - ${cluster} - ${attributes.length}`;
this.queue.push((queueCallback) => {
const configReport = () => {
this.queue.push(ep.device.ieeeAddr, (queueCallback) => {
ep.foundation(cluster, 'configReport', cfgArr, defaultCfg, (error) => {
if (error) {
logger.error(`Failed to setup reporting ${log} - (${error})`);
} else {
logger.debug(`Successfully setup reporting ${log}`);
}
queueCallback(error);
});
});
};
this.queue.push(ep.device.ieeeAddr, (queueCallback) => {
logger.debug(`Setup reporting ${log}`);
ep.bind(cluster, this.getCoordinator(), (error) => {
if (error) {
logger.error(`Failed to bind for reporting ${log} - (${error})`);
} else {
ep.foundation(cluster, 'configReport', cfgArr, defaultCfg, (error) => {
if (error) {
logger.error(`Failed to setup reporting ${log} - (${error})`);
} else {
logger.debug(`Successfully setup reporting ${log}`);
}
});
// Only if binding succeeds, setting-up reporting makes sense.
configReport();
}
queueCallback(error);
});
setTimeout(() => queueCallback(), delay);
});
}
}
module.exports = Zigbee;
module.exports = Zigbee;