Skip to content

Commit

Permalink
fix: Fix duplicate configured reportings Koenkk/zigbee2mqtt#19317
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed Dec 3, 2023
1 parent a3fac45 commit 59c1bbe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/controller/model/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -763,8 +763,10 @@ class Endpoint extends Entity {
}

for (const e of payload) {
this._configuredReportings = this._configuredReportings.filter((c) => !(c.attrId === e.attrId &&
c.cluster === cluster.ID && c.manufacturerCode === options.manufacturerCode));
this._configuredReportings = this._configuredReportings.filter((c) => !(
c.attrId === e.attrId && c.cluster === cluster.ID &&
(!('manufacturerCode' in c) || c.manufacturerCode === options.manufacturerCode)
));
}

for (const entry of payload) {
Expand Down
21 changes: 21 additions & 0 deletions test/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2717,6 +2717,27 @@ describe('Controller', () => {
expect(endpoint.configuredReportings[1].cluster.name).toBe('hvacThermostat');
});

it('Should replace legacy configured reportings without manufacturerCode', async () => {
await controller.start();
await mockAdapterEvents['deviceJoined']({networkAddress: 129, ieeeAddr: '0x129'});
const device = controller.getDeviceByIeeeAddr('0x129');
const endpoint = device.getEndpoint(1);
mocksendZclFrameToEndpoint.mockClear();

endpoint._configuredReportings = [{"cluster":65382,"attrId":5,"minRepIntval":60,"maxRepIntval":900,"repChange":1}]

await endpoint.configureReporting('liXeePrivate', [{
attribute: 'warnDPS',
minimumReportInterval: 1,
maximumReportInterval: 10,
reportableChange: 1,
}])

expect(endpoint.configuredReportings.length).toBe(1);
expect(endpoint.configuredReportings[0].attribute.name).toBe('warnDPS');
expect(endpoint.configuredReportings[0].cluster.name).toBe('liXeePrivate');
});

it('Endpoint configure reporting for manufacturer specific attribute', async () => {
await controller.start();
await mockAdapterEvents['deviceJoined']({networkAddress: 129, ieeeAddr: '0x129'});
Expand Down

0 comments on commit 59c1bbe

Please sign in to comment.