diff --git a/src/adapter/z-stack/adapter/zStackAdapter.ts b/src/adapter/z-stack/adapter/zStackAdapter.ts index b09df76377..28a1a1d4d9 100644 --- a/src/adapter/z-stack/adapter/zStackAdapter.ts +++ b/src/adapter/z-stack/adapter/zStackAdapter.ts @@ -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 { diff --git a/test/adapter/z-stack/adapter.test.ts b/test/adapter/z-stack/adapter.test.ts index 688e215f09..3b9e2ab2bc 100644 --- a/test/adapter/z-stack/adapter.test.ts +++ b/test/adapter/z-stack/adapter.test.ts @@ -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();