Skip to content

Commit

Permalink
emit event on converter triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
slugzero committed Jan 8, 2024
1 parent ce7d022 commit 4dcd10e
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions lib/extension/receive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,39 @@ export default class Receive extends Extension {
utils.publishLastSeen({device: data.device, reason: 'messageEmitted'},
settings.get(), true, this.publishEntityState);
}

// Check for events which should be triggered by this Zigbee message.
// If a valid event is returned, emit the event.
const emit = (events: string[]): void => {
if (events.includes('devicesChanged')) {
this.eventBus.emitDevicesChanged();
}
};

if (!data.device.definition.triggers) {

Check failure on line 173 in lib/extension/receive.ts

View workflow job for this annotation

GitHub Actions / ci

Property 'triggers' does not exist on type 'Definition'.

Check failure on line 173 in lib/extension/receive.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 18)

Property 'triggers' does not exist on type 'Definition'.

Check failure on line 173 in lib/extension/receive.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 20)

Property 'triggers' does not exist on type 'Definition'.

Check failure on line 173 in lib/extension/receive.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 18)

Property 'triggers' does not exist on type 'Definition'.

Check failure on line 173 in lib/extension/receive.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 20)

Property 'triggers' does not exist on type 'Definition'.

Check failure on line 173 in lib/extension/receive.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 18)

Property 'triggers' does not exist on type 'Definition'.

Check failure on line 173 in lib/extension/receive.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 20)

Property 'triggers' does not exist on type 'Definition'.
return;
}

let events: string[] = [];
const triggers = data.device.definition.triggers.filter((t) => {

Check failure on line 178 in lib/extension/receive.ts

View workflow job for this annotation

GitHub Actions / ci

Property 'triggers' does not exist on type 'Definition'.

Check failure on line 178 in lib/extension/receive.ts

View workflow job for this annotation

GitHub Actions / ci

Parameter 't' implicitly has an 'any' type.

Check failure on line 178 in lib/extension/receive.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 18)

Property 'triggers' does not exist on type 'Definition'.

Check failure on line 178 in lib/extension/receive.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 18)

Parameter 't' implicitly has an 'any' type.

Check failure on line 178 in lib/extension/receive.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 20)

Property 'triggers' does not exist on type 'Definition'.

Check failure on line 178 in lib/extension/receive.ts

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest, 20)

Parameter 't' implicitly has an 'any' type.

Check failure on line 178 in lib/extension/receive.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 18)

Property 'triggers' does not exist on type 'Definition'.

Check failure on line 178 in lib/extension/receive.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 18)

Parameter 't' implicitly has an 'any' type.

Check failure on line 178 in lib/extension/receive.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 20)

Property 'triggers' does not exist on type 'Definition'.

Check failure on line 178 in lib/extension/receive.ts

View workflow job for this annotation

GitHub Actions / tests (macos-latest, 20)

Parameter 't' implicitly has an 'any' type.

Check failure on line 178 in lib/extension/receive.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 18)

Property 'triggers' does not exist on type 'Definition'.

Check failure on line 178 in lib/extension/receive.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 18)

Parameter 't' implicitly has an 'any' type.

Check failure on line 178 in lib/extension/receive.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 20)

Property 'triggers' does not exist on type 'Definition'.

Check failure on line 178 in lib/extension/receive.ts

View workflow job for this annotation

GitHub Actions / tests (windows-latest, 20)

Parameter 't' implicitly has an 'any' type.
return t.cluster === data.cluster && t.attribute in data.data;
});
for (const trigger of triggers) {
try {
if (!Array.isArray(data.data)) {
const result = trigger.getEvents(
data.data, data.device.zh);
if (result) {
events = [...events, ...result];
}
}
} catch (error) /* istanbul ignore next */ {
logger.error(`Exception while calling fromZigbee trigger: ${error.message}}`);
logger.debug(error.stack);
}
}
if (events.length) {
emit(events);
}
}
}

0 comments on commit 4dcd10e

Please sign in to comment.