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): save the last source route path to each device state #25205

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
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
8 changes: 8 additions & 0 deletions lib/eventBus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface EventBusMap {
scenesChanged: [data: eventdata.ScenesChanged];
reconfigure: [data: eventdata.Reconfigure];
stateChange: [data: eventdata.StateChange];
sourceRoute: [data: eventdata.SourceRouteChanged];
}
type EventBusListener<K> = K extends keyof EventBusMap
? EventBusMap[K] extends unknown[]
Expand Down Expand Up @@ -194,6 +195,13 @@ export default class EventBus {
this.emitExposesChanged({device});
}

public emitSourceRoute(data: eventdata.SourceRouteChanged): void {
this.emitter.emit('sourceRoute', data);
}
public onSourceRoute(key: ListenerKey, callback: (data: eventdata.SourceRouteChanged) => void): void {
this.on('sourceRoute', callback, key);
}

private on<K extends keyof EventBusMap>(event: K, callback: EventBusListener<K>, key: ListenerKey): void {
if (!this.callbacksByExtension[key.constructor.name]) {
this.callbacksByExtension[key.constructor.name] = [];
Expand Down
11 changes: 11 additions & 0 deletions lib/extension/receive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default class Receive extends Extension {
async start(): Promise<void> {
this.eventBus.onPublishEntityState(this, this.onPublishEntityState);
this.eventBus.onDeviceMessage(this, this.onDeviceMessage);
this.eventBus.onSourceRoute(this, this.onSourceRouteChanged);
}

@bind async onPublishEntityState(data: eventdata.PublishEntityState): Promise<void> {
Expand Down Expand Up @@ -183,4 +184,14 @@ export default class Receive extends Extension {
await utils.publishLastSeen({device: data.device, reason: 'messageEmitted'}, settings.get(), true, this.publishEntityState);
}
}

@bind async onSourceRouteChanged(data: eventdata.SourceRouteChanged): Promise<void> {
const device = this.zigbee.resolveEntity(data.device.ieeeAddr);
if (!device) {
logger.warning(`Source route indication received for unknown device '${data.device.ieeeAddr}'`);
return;
}
logger.debug(`Source route indication received for '${device.name}'`);
this.state.set(device, {source_route: data.relaylist});
}
}
6 changes: 6 additions & 0 deletions lib/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ declare global {
meta: {zclTransactionSequenceNumber?: number; manufacturerCode?: number; frameControl?: ZHFrameControl};
};
type ScenesChanged = {entity: Device | Group};
type SourceRouteChanged = {
device: zh.Device;
dstaddr: number;
relaycount: number;
relaylist: number[];
};
}

// Settings
Expand Down
9 changes: 9 additions & 0 deletions lib/zigbee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@
if (device.zh.type === 'Coordinator') return;
this.eventBus.emitDeviceMessage({...data, device});
});
this.herdsman.on('sourceRoute', (data: ZHEvents.SrcRouteIndPayload) => {

Check failure on line 126 in lib/zigbee.ts

View workflow job for this annotation

GitHub Actions / ci

Argument of type '(data: ZHEvents.SrcRouteIndPayload) => void' is not assignable to parameter of type 'never'.

Check failure on line 126 in lib/zigbee.ts

View workflow job for this annotation

GitHub Actions / ci

Namespace '"/home/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/.pnpm/[email protected]/node_modules/zigbee-herdsman/dist/controller/events"' has no exported member 'SrcRouteIndPayload'.

Check failure on line 126 in lib/zigbee.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 18)

Argument of type '(data: ZHEvents.SrcRouteIndPayload) => void' is not assignable to parameter of type 'never'.

Check failure on line 126 in lib/zigbee.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 18)

Namespace '"/home/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/.pnpm/[email protected]/node_modules/zigbee-herdsman/dist/controller/events"' has no exported member 'SrcRouteIndPayload'.

Check failure on line 126 in lib/zigbee.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 20)

Argument of type '(data: ZHEvents.SrcRouteIndPayload) => void' is not assignable to parameter of type 'never'.

Check failure on line 126 in lib/zigbee.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 20)

Namespace '"/home/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/.pnpm/[email protected]/node_modules/zigbee-herdsman/dist/controller/events"' has no exported member 'SrcRouteIndPayload'.

Check failure on line 126 in lib/zigbee.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 22)

Argument of type '(data: ZHEvents.SrcRouteIndPayload) => void' is not assignable to parameter of type 'never'.

Check failure on line 126 in lib/zigbee.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 22)

Namespace '"/home/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/.pnpm/[email protected]/node_modules/zigbee-herdsman/dist/controller/events"' has no exported member 'SrcRouteIndPayload'.

Check failure on line 126 in lib/zigbee.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 18)

Argument of type '(data: ZHEvents.SrcRouteIndPayload) => void' is not assignable to parameter of type 'never'.

Check failure on line 126 in lib/zigbee.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 18)

Namespace '"/Users/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/.pnpm/[email protected]/node_modules/zigbee-herdsman/dist/controller/events"' has no exported member 'SrcRouteIndPayload'.

Check failure on line 126 in lib/zigbee.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 20)

Argument of type '(data: ZHEvents.SrcRouteIndPayload) => void' is not assignable to parameter of type 'never'.

Check failure on line 126 in lib/zigbee.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 20)

Namespace '"/Users/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/.pnpm/[email protected]/node_modules/zigbee-herdsman/dist/controller/events"' has no exported member 'SrcRouteIndPayload'.

Check failure on line 126 in lib/zigbee.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 22)

Argument of type '(data: ZHEvents.SrcRouteIndPayload) => void' is not assignable to parameter of type 'never'.

Check failure on line 126 in lib/zigbee.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 22)

Namespace '"/Users/runner/work/zigbee2mqtt/zigbee2mqtt/node_modules/.pnpm/[email protected]/node_modules/zigbee-herdsman/dist/controller/events"' has no exported member 'SrcRouteIndPayload'.

Check failure on line 126 in lib/zigbee.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 18)

Argument of type '(data: ZHEvents.SrcRouteIndPayload) => void' is not assignable to parameter of type 'never'.

Check failure on line 126 in lib/zigbee.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 18)

Namespace '"D:/a/zigbee2mqtt/zigbee2mqtt/node_modules/.pnpm/[email protected]/node_modules/zigbee-herdsman/dist/controller/events"' has no exported member 'SrcRouteIndPayload'.

Check failure on line 126 in lib/zigbee.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 20)

Argument of type '(data: ZHEvents.SrcRouteIndPayload) => void' is not assignable to parameter of type 'never'.

Check failure on line 126 in lib/zigbee.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 20)

Namespace '"D:/a/zigbee2mqtt/zigbee2mqtt/node_modules/.pnpm/[email protected]/node_modules/zigbee-herdsman/dist/controller/events"' has no exported member 'SrcRouteIndPayload'.

Check failure on line 126 in lib/zigbee.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 22)

Argument of type '(data: ZHEvents.SrcRouteIndPayload) => void' is not assignable to parameter of type 'never'.

Check failure on line 126 in lib/zigbee.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 22)

Namespace '"D:/a/zigbee2mqtt/zigbee2mqtt/node_modules/.pnpm/[email protected]/node_modules/zigbee-herdsman/dist/controller/events"' has no exported member 'SrcRouteIndPayload'.
logger.debug(`Source route indication received: ${stringify(data)}`);
const device = this.herdsman.getDeviceByNetworkAddress(data.dstaddr);
if (!device) {
logger.warning(`Source route indication received for unknown device '${data.dstaddr}'`);
return;
}
this.eventBus.emitSourceRoute({device: device, ...data});
});

logger.info(`zigbee-herdsman started (${startResult})`);
logger.info(`Coordinator firmware version: '${stringify(await this.getCoordinatorVersion())}'`);
Expand Down
Loading