Skip to content

Commit

Permalink
fix: On NO_ENTRY error during unbind cleanup database (#1206)
Browse files Browse the repository at this point in the history
* initial implementation
* rework for reviewer feedback

Co-authored-by: Nerivec
  • Loading branch information
sjorge committed Sep 29, 2024
1 parent 854e5f3 commit 01b76ff
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
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

0 comments on commit 01b76ff

Please sign in to comment.