diff --git a/lib/zigbee.js b/lib/zigbee.js index 601bba8d..b0085e18 100644 --- a/lib/zigbee.js +++ b/lib/zigbee.js @@ -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; \ No newline at end of file +module.exports = Zigbee;