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

(feat): add an event exposing source routing information #1264

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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 @@
zdoResponse: [clusterId: Zdo.ClusterId, response: ZdoTypes.GenericZdoResponse];
disconnected: [];
deviceLeave: [payload: AdapterEvents.DeviceLeavePayload];
sourceRoute: [payload: any];

Check failure on line 18 in src/adapter/adapter.ts

View workflow job for this annotation

GitHub Actions / ci

Unexpected any. Specify a different type
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be typed too? When I tried I was getting typing errors in the emit line in the zstack adapter class, but I didn't get much deeper than that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CI check would indicate that yes, I should fix this!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely needs typing, and definitely needs to be a generic form that works with all adapters (not the payload of zstack). Although, it's unlikely some adapters will even be able to support this.

}

abstract class Adapter extends events.EventEmitter<AdapterEventMap> {
Expand Down
2 changes: 2 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,8 @@ 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,
};
Loading