From 10e42fdc0cdbc0c00360b03954101532dda02a99 Mon Sep 17 00:00:00 2001 From: Andrew Berry Date: Thu, 28 Mar 2024 15:56:48 -0400 Subject: [PATCH] fix: ZStack: emit network address change event on concentratorIndCb (#992) * Emit nwk event on concentratorIndCb * Explain why we send an event that doesn't match the command * Test that we send the network update event on concentratorIndCb --- src/adapter/z-stack/adapter/zStackAdapter.ts | 17 +++++++++++++++++ test/adapter/z-stack/adapter.test.ts | 10 ++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/adapter/z-stack/adapter/zStackAdapter.ts b/src/adapter/z-stack/adapter/zStackAdapter.ts index f411c322b3..64f76421fd 100644 --- a/src/adapter/z-stack/adapter/zStackAdapter.ts +++ b/src/adapter/z-stack/adapter/zStackAdapter.ts @@ -792,6 +792,23 @@ class ZStackAdapter extends Adapter { ieeeAddr: object.payload.ieeeaddr, }; + this.emit(Events.Events.networkAddress, payload); + } else if (object.command === 'concentratorIndCb') { + // Some routers may change short addresses and the announcement + // is missed by the coordinator. This can happen when there are + // power outages or other interruptions in service. They may + // not send additional announcements, causing the device to go + // offline. However, those devices may instead send + // Concentrator Indicator Callback commands, which contain both + // the short and the long address allowing us to update our own + // mappings. + // https://e2e.ti.com/cfs-file/__key/communityserver-discussions-components-files/158/4403.zstacktask.c + // https://github.com/Koenkk/zigbee-herdsman/issues/74 + const payload: Events.NetworkAddressPayload = { + networkAddress: object.payload.srcaddr, + ieeeAddr: object.payload.extaddr, + }; + this.emit(Events.Events.networkAddress, payload); } else { /* istanbul ignore else */ diff --git a/test/adapter/z-stack/adapter.test.ts b/test/adapter/z-stack/adapter.test.ts index 64859feef2..cafd28c929 100644 --- a/test/adapter/z-stack/adapter.test.ts +++ b/test/adapter/z-stack/adapter.test.ts @@ -2781,6 +2781,16 @@ describe("zstack-adapter", () => { expect(networkAddress).toStrictEqual({ieeeAddr: '0x123', networkAddress: 124}); }); + it('Concentrator Callback Indication', async () => { + basicMocks(); + await adapter.start(); + let networkAddress; + const object = {type: Type.AREQ, subsystem: Subsystem.ZDO, command: 'concentratorIndCb', payload: {srcaddr: 124, extaddr: '0x123'}}; + adapter.on("networkAddress", (p) => {networkAddress = p;}) + znpReceived(object); + expect(networkAddress).toStrictEqual({ieeeAddr: '0x123', networkAddress: 124}); + }); + it('Device leave', async () => { basicMocks(); await adapter.start();