Skip to content

Commit

Permalink
fix: ZStack: emit network address change event on concentratorIndCb (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
deviantintegral authored Mar 28, 2024
1 parent aac0732 commit 10e42fd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/adapter/z-stack/adapter/zStackAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
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 @@ -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();
Expand Down

0 comments on commit 10e42fd

Please sign in to comment.