Skip to content

Commit

Permalink
do not remove device if leave indication has rejoin flag set
Browse files Browse the repository at this point in the history
  • Loading branch information
slugzero committed Dec 16, 2023
1 parent 0513221 commit 8f4275c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/adapter/z-stack/adapter/zStackAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -795,12 +795,16 @@ class ZStackAdapter extends Adapter {
} else {
/* istanbul ignore else */
if (object.command === 'leaveInd') {
const payload: Events.DeviceLeavePayload = {
networkAddress: object.payload.srcaddr,
ieeeAddr: object.payload.extaddr,
};
if (object.payload?.rejoin) {
debug(`Device leave: Got leave indication with rejoin=true, nothing to do`);
} else {
const payload: Events.DeviceLeavePayload = {
networkAddress: object.payload.srcaddr,
ieeeAddr: object.payload.extaddr,
};

this.emit(Events.Events.deviceLeave, payload);
this.emit(Events.Events.deviceLeave, payload);
}
}
}
} else {
Expand Down
10 changes: 10 additions & 0 deletions test/adapter/z-stack/adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2775,6 +2775,16 @@ describe("zstack-adapter", () => {
expect(deviceAnnounce).toStrictEqual({ieeeAddr: '0x123', networkAddress: 123});
});

it('Ignore device leave with rejoin', async () => {
basicMocks();
await adapter.start();
let deviceAnnounce;
const object = {type: Type.AREQ, subsystem: Subsystem.ZDO, command: 'leaveInd', payload: {srcaddr: 123, extaddr: '0x123', rejoin: true},};
adapter.on("deviceLeave", (p) => {deviceAnnounce = p;})
znpReceived(object);
expect(deviceAnnounce).toStrictEqual(undefined);
});

it('Do nothing wiht non areq event', async () => {
basicMocks();
await adapter.start();
Expand Down

0 comments on commit 8f4275c

Please sign in to comment.