Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit nwk event on concentratorIndCb #992

Merged
merged 3 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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