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: On NO_ENTRY error during unbind cleanup database #1206

Merged
merged 1 commit into from
Sep 29, 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
6 changes: 5 additions & 1 deletion src/controller/model/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,11 @@ class Endpoint extends Entity {
const response = await Entity.adapter!.sendZdo(this.deviceIeeeAddress, this.deviceNetworkAddress, zdoClusterId, zdoPayload, false);

if (!Zdo.Buffalo.checkStatus(response)) {
throw new Zdo.StatusError(response[0]);
if (response[0] === Zdo.Status.NO_ENTRY) {
logger.debug(`${log} no entry on device, removing entry from database.`, NS);
} else {
throw new Zdo.StatusError(response[0]);
}
}

this._binds.splice(index, 1);
Expand Down
28 changes: 28 additions & 0 deletions test/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7995,6 +7995,34 @@ describe('Controller', () => {
expect(error).toStrictEqual(new Error(`Unbind 0x129/1 genOnOff invalid target '1' (no group with this ID exists).`));
});

it('Unbind against unbound cluster', async () => {
await controller.start();
await mockAdapterEvents['deviceJoined']({networkAddress: 129, ieeeAddr: '0x129'});
await mockAdapterEvents['deviceJoined']({networkAddress: 170, ieeeAddr: '0x170'});
const endpoint = controller.getDeviceByIeeeAddr('0x129')!.getEndpoint(1)!;
const target = controller.getDeviceByIeeeAddr('0x170')!.getEndpoint(1)!;
await endpoint.bind('genOnOff', target);
mockAdapterSendZdo.mockClear();

sendZdoResponseStatus = Zdo.Status.NO_ENTRY;

await endpoint.unbind('genOnOff', target);

const zdoPayload = Zdo.Buffalo.buildRequest(
false,
Zdo.ClusterId.UNBIND_REQUEST,
'0x129',
1,
Zcl.Clusters.genOnOff.ID,
Zdo.UNICAST_BINDING,
'0x170',
0,
1,
);
expect(mockAdapterSendZdo).toHaveBeenCalledWith('0x129', 129, Zdo.ClusterId.UNBIND_REQUEST, zdoPayload, false);
expect(endpoint.binds).toStrictEqual([]);
});

it('Unbind error', async () => {
await controller.start();
await mockAdapterEvents['deviceJoined']({networkAddress: 129, ieeeAddr: '0x129'});
Expand Down