Skip to content

Commit

Permalink
fix(fire-event)!: Only render templates/expressions when not from mes…
Browse files Browse the repository at this point in the history
…sage input

BREAKING-CHANGE: Mustache templates or JSONata expression being passed into the fire-event node will no longer be rendered
  • Loading branch information
zachowj committed May 6, 2024
1 parent 1d2b507 commit 16e8e22
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/nodes/fire-event/FireEventController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import NoConnectionError from '../../common/errors/NoConnectionError';
import { TypedInputTypes } from '../../const';
import { renderTemplate } from '../../helpers/mustache';
import { FireEventNode, FireEventNodeProperties } from '.';
import { DataSource } from '../../common/services/InputService';
import { event } from 'jquery';

Check failure on line 9 in src/nodes/fire-event/FireEventController.ts

View workflow job for this annotation

GitHub Actions / Tests (Node 16 - node-red ^3)

'event' is defined but never used

Check failure on line 9 in src/nodes/fire-event/FireEventController.ts

View workflow job for this annotation

GitHub Actions / Tests (Node 16 - node-red 3.1.1)

'event' is defined but never used

Check failure on line 9 in src/nodes/fire-event/FireEventController.ts

View workflow job for this annotation

GitHub Actions / Tests (Node 18 - node-red ^3)

'event' is defined but never used

Check failure on line 9 in src/nodes/fire-event/FireEventController.ts

View workflow job for this annotation

GitHub Actions / Tests (Node 18 - node-red 3.1.1)

'event' is defined but never used

Check failure on line 9 in src/nodes/fire-event/FireEventController.ts

View workflow job for this annotation

GitHub Actions / Tests (Node 20 - node-red ^3)

'event' is defined but never used

Check failure on line 9 in src/nodes/fire-event/FireEventController.ts

View workflow job for this annotation

GitHub Actions / Tests (Node 20 - node-red 3.1.1)

'event' is defined but never used

export default class FireEventController extends InputOutputController<
FireEventNode,
Expand All @@ -20,14 +22,20 @@ export default class FireEventController extends InputOutputController<
throw new NoConnectionError();
}

const eventType = renderTemplate(
parsedMessage.event.value,
message,
this.node.context(),
this.homeAssistant.websocket.getStates(),
);
let eventData: any;
if (parsedMessage.data.value) {
const eventType =
parsedMessage.event.source === DataSource.Message
? parsedMessage.event.value
: renderTemplate(
parsedMessage.event.value,
message,
this.node.context(),
this.homeAssistant.websocket.getStates(),
);

let eventData: unknown;
if (parsedMessage.data.source === DataSource.Message) {
eventData = parsedMessage.data.value;
} else if (parsedMessage.data.value) {
if (parsedMessage.dataType.value === TypedInputTypes.JSONata) {
eventData = await this.jsonataService.evaluate(
parsedMessage.data.value,
Expand Down

0 comments on commit 16e8e22

Please sign in to comment.