This commit is contained in:
Koen Kanters
2019-10-12 18:02:15 +02:00
parent 5e0d72c41c
commit d5925efca7
2 changed files with 18 additions and 1 deletions
+4 -1
View File
@@ -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();
+14
View File
@@ -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);
});
});