Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove disappeared endpoints #1227

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/controller/model/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1074,8 +1074,6 @@ class Device extends Entity<ControllerEventMap> {

// Make sure that the endpoint are sorted.
activeEndpoints.endpointList.sort((a, b) => a - b);

// TODO: this does not take care of removing endpoint (changing custom devices)?
for (const endpoint of activeEndpoints.endpointList) {
// Some devices, e.g. TERNCY return endpoint 0 in the active endpoints request.
// This is not a valid endpoint number according to the ZCL, requesting a simple descriptor will result
Expand All @@ -1085,6 +1083,9 @@ class Device extends Entity<ControllerEventMap> {
this._endpoints.push(Endpoint.create(endpoint, undefined, undefined, [], [], this.networkAddress, this.ieeeAddr));
}
}

// Remove disappeared endpoints (can happen with e.g. custom devices).
this._endpoints = this._endpoints.filter((e) => activeEndpoints.endpointList.includes(e.ID));
}

/**
Expand Down
14 changes: 13 additions & 1 deletion test/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import * as Events from '../src/controller/events';
import Request from '../src/controller/helpers/request';
import zclTransactionSequenceNumber from '../src/controller/helpers/zclTransactionSequenceNumber';
import ZclTransactionSequenceNumber from '../src/controller/helpers/zclTransactionSequenceNumber';
import {Device, Group} from '../src/controller/model';
import {Device, Endpoint, Group} from '../src/controller/model';
import * as Models from '../src/models';
import {Wait} from '../src/utils';
import * as Utils from '../src/utils';
Expand Down Expand Up @@ -4037,6 +4037,18 @@ describe('Controller', () => {
expect(mockAdapterSendZdo).toHaveBeenCalledTimes(8); // nodeDesc + activeEp + simpleDesc x1
});

it('Should remove disappeared endpoints on updateActiveEndpoints', async () => {
await controller.start();
mockAdapterSendZdo.mockClear();
await mockAdapterEvents['deviceJoined']({networkAddress: 129, ieeeAddr: '0x129'});

const device = controller.getDeviceByIeeeAddr('0x129')!;
device.endpoints.push(Endpoint.create(2, undefined, undefined, [], [], device.networkAddress, device.ieeeAddr));
expect(device.endpoints.map((e) => e.ID)).toStrictEqual([1, 2]);
await device.updateActiveEndpoints();
expect(device.endpoints.map((e) => e.ID)).toStrictEqual([1]);
});

it('Receive zclData report from unkown attribute', async () => {
await controller.start();
await mockAdapterEvents['deviceJoined']({networkAddress: 129, ieeeAddr: '0x129'});
Expand Down