Skip to content

Commit c079cf5

Browse files
committed
fix: On NO_ENTRY error during unbind cleanup database
* initial implementation * rework for reviewer feedback
1 parent 5d02efe commit c079cf5

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/controller/model/endpoint.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,11 @@ class Endpoint extends Entity {
621621
const response = await Entity.adapter!.sendZdo(this.deviceIeeeAddress, this.deviceNetworkAddress, zdoClusterId, zdoPayload, false);
622622

623623
if (!Zdo.Buffalo.checkStatus(response)) {
624-
throw new Zdo.StatusError(response[0]);
624+
if (response[0] === Zdo.Status.NO_ENTRY) {
625+
logger.debug(`${log} no entry on device, removing entry from database.`, NS);
626+
} else {
627+
throw new Zdo.StatusError(response[0]);
628+
}
625629
}
626630

627631
this._binds.splice(index, 1);

test/controller.test.ts

+28
Original file line numberDiff line numberDiff line change
@@ -7995,6 +7995,34 @@ describe('Controller', () => {
79957995
expect(error).toStrictEqual(new Error(`Unbind 0x129/1 genOnOff invalid target '1' (no group with this ID exists).`));
79967996
});
79977997

7998+
it('Unbind against unbound cluster', async () => {
7999+
await controller.start();
8000+
await mockAdapterEvents['deviceJoined']({networkAddress: 129, ieeeAddr: '0x129'});
8001+
await mockAdapterEvents['deviceJoined']({networkAddress: 170, ieeeAddr: '0x170'});
8002+
const endpoint = controller.getDeviceByIeeeAddr('0x129')!.getEndpoint(1)!;
8003+
const target = controller.getDeviceByIeeeAddr('0x170')!.getEndpoint(1)!;
8004+
await endpoint.bind('genOnOff', target);
8005+
mockAdapterSendZdo.mockClear();
8006+
8007+
sendZdoResponseStatus = Zdo.Status.NO_ENTRY;
8008+
8009+
await endpoint.unbind('genOnOff', target);
8010+
8011+
const zdoPayload = Zdo.Buffalo.buildRequest(
8012+
false,
8013+
Zdo.ClusterId.UNBIND_REQUEST,
8014+
'0x129',
8015+
1,
8016+
Zcl.Clusters.genOnOff.ID,
8017+
Zdo.UNICAST_BINDING,
8018+
'0x170',
8019+
0,
8020+
1,
8021+
);
8022+
expect(mockAdapterSendZdo).toHaveBeenCalledWith('0x129', 129, Zdo.ClusterId.UNBIND_REQUEST, zdoPayload, false);
8023+
expect(endpoint.binds).toStrictEqual([]);
8024+
});
8025+
79988026
it('Unbind error', async () => {
79998027
await controller.start();
80008028
await mockAdapterEvents['deviceJoined']({networkAddress: 129, ieeeAddr: '0x129'});

0 commit comments

Comments
 (0)