diff --git a/src/data/automation.ts b/src/data/automation.ts index d4eaa843c7..97395806db 100644 --- a/src/data/automation.ts +++ b/src/data/automation.ts @@ -3,7 +3,7 @@ import { HassEntityBase, } from "home-assistant-js-websocket"; import { navigate } from "../common/navigate"; -import { HomeAssistant } from "../types"; +import { HomeAssistant, Context } from "../types"; import { DeviceCondition, DeviceTrigger } from "./device_automation"; import { Action } from "./script"; @@ -206,3 +206,31 @@ export const getAutomationEditorInitData = () => { inititialAutomationEditorData = undefined; return data; }; + +export const subscribeTrigger = ( + hass: HomeAssistant, + onChange: (result: { + variables: { + trigger: {}; + }; + context: Context; + }) => void, + trigger: Trigger | Trigger[], + variables?: {} +) => + hass.connection.subscribeMessage(onChange, { + type: "subscribe_trigger", + trigger, + variables, + }); + +export const testCondition = ( + hass: HomeAssistant, + condition: Condition | Condition[], + variables?: {} +) => + hass.callWS<{ result: boolean }>({ + type: "test_condition", + condition, + variables, + }); diff --git a/src/types.ts b/src/types.ts index a6f27ee768..ddd285cf93 100644 --- a/src/types.ts +++ b/src/types.ts @@ -193,7 +193,7 @@ export interface Resources { export interface Context { id: string; - parrent_id?: string; + parent_id?: string; user_id?: string; }