Skip to content

Commit

Permalink
Add an event exposing source routing information
Browse files Browse the repository at this point in the history
  • Loading branch information
deviantintegral committed Dec 14, 2024
1 parent 855fe7a commit 0becd51
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/adapter/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface AdapterEventMap {
zdoResponse: [clusterId: Zdo.ClusterId, response: ZdoTypes.GenericZdoResponse];
disconnected: [];
deviceLeave: [payload: AdapterEvents.DeviceLeavePayload];
sourceRoute: [payload: any];
}

abstract class Adapter extends events.EventEmitter<AdapterEventMap> {
Expand Down
3 changes: 3 additions & 0 deletions src/adapter/z-stack/adapter/zStackAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,9 @@ class ZStackAdapter extends Adapter {
};

this.emit('deviceJoined', payload);
}
else if (object.command.name === 'srcRtgInd') {
this.emit('sourceRoute', object.payload);
} else if (object.command.name === 'endDeviceAnnceInd') {
// TODO: better way???
/* istanbul ignore else */
Expand Down
6 changes: 6 additions & 0 deletions src/controller/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export interface ControllerEventMap {
deviceLeave: [data: Events.DeviceLeavePayload];
permitJoinChanged: [data: Events.PermitJoinChangedPayload];
lastSeenChanged: [data: Events.LastSeenChangedPayload];
sourceRoute: [data: Events.SrcRouteIndPayload];
}

/**
Expand Down Expand Up @@ -165,6 +166,7 @@ class Controller extends events.EventEmitter<ControllerEventMap> {
this.adapter.on('zdoResponse', this.onZdoResponse.bind(this));
this.adapter.on('disconnected', this.onAdapterDisconnected.bind(this));
this.adapter.on('deviceLeave', this.onDeviceLeave.bind(this));
this.adapter.on('sourceRoute', this.onSourceRoute.bind(this));

if (startResult === 'reset') {
/* istanbul ignore else */
Expand Down Expand Up @@ -958,6 +960,10 @@ class Controller extends events.EventEmitter<ControllerEventMap> {
await device.onZclData(payload, frame, endpoint);
}
}

private onSourceRoute(data: Events.SrcRouteIndPayload): void {
this.emit('sourceRoute', data);
}
}

export default Controller;
7 changes: 7 additions & 0 deletions src/controller/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ interface MessagePayload {
};
}

interface SrcRouteIndPayload {
dstaddr: number;
relaycount: number;
relaylist: number[];
}

export {
MessagePayload,
MessagePayloadType,
Expand All @@ -60,4 +66,5 @@ export {
PermitJoinChangedPayload,
DeviceNetworkAddressChangedPayload,
LastSeenChangedPayload,
SrcRouteIndPayload,
};

0 comments on commit 0becd51

Please sign in to comment.