From d5925efca78575692d47b6343473486367ccc266 Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Sat, 12 Oct 2019 18:02:15 +0200 Subject: [PATCH] Only try to configure reporting once. https://github.com/Koenkk/zigbee2mqtt/issues/2123 --- lib/extension/deviceReport.js | 5 ++++- test/deviceReport.test.js | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/extension/deviceReport.js b/lib/extension/deviceReport.js index 6faa855f8..82a1fbd01 100644 --- a/lib/extension/deviceReport.js +++ b/lib/extension/deviceReport.js @@ -32,10 +32,11 @@ class DeviceReport extends BaseExtension { constructor(zigbee, mqtt, state, publishEntityState) { super(zigbee, mqtt, state, publishEntityState); this.configuring = new Set(); + this.failed = new Set(); } async setupReporting(device) { - if (this.configuring.has(device.ieeeAddr)) return; + if (this.configuring.has(device.ieeeAddr) || this.failed.has(device.ieeeAddr)) return; this.configuring.add(device.ieeeAddr); try { @@ -58,6 +59,8 @@ class DeviceReport extends BaseExtension { logger.error( `Failed to setup reporting for '${device.ieeeAddr}' - ${error.stack}` ); + + this.failed.add(device.ieeeAddr); } device.save(); diff --git a/test/deviceReport.test.js b/test/deviceReport.test.js index e7869ed60..7e68c9c9a 100644 --- a/test/deviceReport.test.js +++ b/test/deviceReport.test.js @@ -149,4 +149,18 @@ describe('Device report', () => { expect(endpoint.bind).toHaveBeenCalledTimes(0); expect(endpoint.configureReporting).toHaveBeenCalledTimes(0); }); + + it('Should not configure reporting again when it already failed once', async () => { + const device = zigbeeHerdsman.devices.bulb; + const endpoint = device.getEndpoint(1); + endpoint.bind.mockImplementationOnce(async () => {throw new Error('failed')}); + delete device.meta.reporting; + mockClear(device); + const payload = {data: {onOff: 1}, cluster: 'genOnOff', device, endpoint: device.getEndpoint(1), type: 'attributeReport', linkquality: 10}; + await zigbeeHerdsman.events.message(payload); + await flushPromises(); + await zigbeeHerdsman.events.message(payload); + await flushPromises(); + expect(endpoint.bind).toHaveBeenCalledTimes(1); + }); });