diff --git a/gallery/src/data/traces/basic_trace.ts b/gallery/src/data/traces/basic_trace.ts index aa2a597f493b..22613244d775 100644 --- a/gallery/src/data/traces/basic_trace.ts +++ b/gallery/src/data/traces/basic_trace.ts @@ -219,7 +219,7 @@ export const basicTrace: DemoTrace = { description: "", triggers: [ { - platform: "state", + trigger: "state", entity_id: "input_boolean.toggle_1", }, ], diff --git a/gallery/src/data/traces/motion-light-trace.ts b/gallery/src/data/traces/motion-light-trace.ts index b212f99760d7..371cd7056a05 100644 --- a/gallery/src/data/traces/motion-light-trace.ts +++ b/gallery/src/data/traces/motion-light-trace.ts @@ -135,7 +135,7 @@ export const motionLightTrace: DemoTrace = { max_exceeded: "silent", triggers: [ { - platform: "state", + trigger: "state", entity_id: "binary_sensor.pauluss_macbook_pro_camera_in_use", from: "off", to: "on", diff --git a/gallery/src/pages/automation/describe-action.ts b/gallery/src/pages/automation/describe-action.ts index d49527337c79..39544cc7f2e4 100644 --- a/gallery/src/pages/automation/describe-action.ts +++ b/gallery/src/pages/automation/describe-action.ts @@ -48,7 +48,7 @@ const ACTIONS = [ { wait_for_trigger: [ { - platform: "state", + trigger: "state", entity_id: "input_boolean.toggle_1", }, ], diff --git a/gallery/src/pages/automation/describe-trigger.ts b/gallery/src/pages/automation/describe-trigger.ts index 476df572673f..f8b8117a83f8 100644 --- a/gallery/src/pages/automation/describe-trigger.ts +++ b/gallery/src/pages/automation/describe-trigger.ts @@ -22,46 +22,46 @@ const ENTITIES = [ ]; const triggers = [ - { platform: "state", entity_id: "light.kitchen", from: "off", to: "on" }, - { platform: "mqtt" }, + { trigger: "state", entity_id: "light.kitchen", from: "off", to: "on" }, + { trigger: "mqtt" }, { - platform: "geo_location", + trigger: "geo_location", source: "test_source", zone: "zone.home", event: "enter", }, - { platform: "homeassistant", event: "start" }, + { trigger: "homeassistant", event: "start" }, { - platform: "numeric_state", + trigger: "numeric_state", entity_id: "light.kitchen", attribute: "brightness", below: 80, above: 20, }, - { platform: "sun", event: "sunset" }, - { platform: "time_pattern" }, - { platform: "time_pattern", hours: "*", minutes: "/5", seconds: "10" }, - { platform: "webhook" }, - { platform: "persistent_notification" }, + { trigger: "sun", event: "sunset" }, + { trigger: "time_pattern" }, + { trigger: "time_pattern", hours: "*", minutes: "/5", seconds: "10" }, + { trigger: "webhook" }, + { trigger: "persistent_notification" }, { - platform: "zone", + trigger: "zone", entity_id: "person.person", zone: "zone.home", event: "enter", }, - { platform: "tag" }, - { platform: "time", at: "15:32" }, - { platform: "template" }, - { platform: "conversation", command: "Turn on the lights" }, + { trigger: "tag" }, + { trigger: "time", at: "15:32" }, + { trigger: "template" }, + { trigger: "conversation", command: "Turn on the lights" }, { - platform: "conversation", + trigger: "conversation", command: ["Turn on the lights", "Turn the lights on"], }, - { platform: "event", event_type: "homeassistant_started" }, + { trigger: "event", event_type: "homeassistant_started" }, ]; const initialTrigger: Trigger = { - platform: "state", + trigger: "state", entity_id: "light.kitchen", }; diff --git a/gallery/src/pages/automation/editor-trigger.ts b/gallery/src/pages/automation/editor-trigger.ts index bb79f63a7104..a138a46e9efa 100644 --- a/gallery/src/pages/automation/editor-trigger.ts +++ b/gallery/src/pages/automation/editor-trigger.ts @@ -111,7 +111,7 @@ const SCHEMAS: { name: string; triggers: Trigger[] }[] = [ triggers: [ { ...HaConversationTrigger.defaultConfig }, { - platform: "conversation", + trigger: "conversation", command: ["Turn on the lights", "Turn the lights on"], }, ], diff --git a/src/components/device/ha-device-trigger-picker.ts b/src/components/device/ha-device-trigger-picker.ts index c5755f9ecd49..9d3f41fdf869 100644 --- a/src/components/device/ha-device-trigger-picker.ts +++ b/src/components/device/ha-device-trigger-picker.ts @@ -26,7 +26,7 @@ class HaDeviceTriggerPicker extends HaDeviceAutomationPicker { fetchDeviceTriggers, (deviceId?: string) => ({ device_id: deviceId || "", - platform: "device", + trigger: "device", domain: "", entity_id: "", }) diff --git a/src/components/ha-selector/ha-selector-action.ts b/src/components/ha-selector/ha-selector-action.ts index 6ee30b5e675d..23d93a2a2999 100644 --- a/src/components/ha-selector/ha-selector-action.ts +++ b/src/components/ha-selector/ha-selector-action.ts @@ -1,6 +1,7 @@ import { css, CSSResultGroup, html, LitElement, nothing } from "lit"; import { customElement, property } from "lit/decorators"; -import { Action } from "../../data/script"; +import memoizeOne from "memoize-one"; +import { Action, migrateAutomationAction } from "../../data/script"; import { ActionSelector } from "../../data/selector"; import "../../panels/config/automation/action/ha-automation-action"; import { HomeAssistant } from "../../types"; @@ -17,12 +18,19 @@ export class HaActionSelector extends LitElement { @property({ type: Boolean, reflect: true }) public disabled = false; + private _actions = memoizeOne((action: Action | undefined) => { + if (!action) { + return []; + } + return migrateAutomationAction(action); + }); + protected render() { return html` ${this.label ? html`` : nothing} diff --git a/src/components/ha-selector/ha-selector-template.ts b/src/components/ha-selector/ha-selector-template.ts index 3ecccf02c5ed..d9ea56fe242b 100644 --- a/src/components/ha-selector/ha-selector-template.ts +++ b/src/components/ha-selector/ha-selector-template.ts @@ -7,12 +7,7 @@ import "../ha-code-editor"; import "../ha-input-helper-text"; import "../ha-alert"; -const WARNING_STRINGS = [ - "template:", - "sensor:", - "state:", - "platform: template", -]; +const WARNING_STRINGS = ["template:", "sensor:", "state:", "trigger: template"]; @customElement("ha-selector-template") export class HaTemplateSelector extends LitElement { diff --git a/src/components/ha-selector/ha-selector-trigger.ts b/src/components/ha-selector/ha-selector-trigger.ts index af4b814a76f9..0974a31702cd 100644 --- a/src/components/ha-selector/ha-selector-trigger.ts +++ b/src/components/ha-selector/ha-selector-trigger.ts @@ -1,6 +1,7 @@ import { css, CSSResultGroup, html, LitElement, nothing } from "lit"; import { customElement, property } from "lit/decorators"; -import { Trigger } from "../../data/automation"; +import memoizeOne from "memoize-one"; +import { migrateAutomationTrigger, Trigger } from "../../data/automation"; import { TriggerSelector } from "../../data/selector"; import "../../panels/config/automation/trigger/ha-automation-trigger"; import { HomeAssistant } from "../../types"; @@ -17,12 +18,19 @@ export class HaTriggerSelector extends LitElement { @property({ type: Boolean, reflect: true }) public disabled = false; + private _triggers = memoizeOne((trigger: Trigger | undefined) => { + if (!trigger) { + return []; + } + return migrateAutomationTrigger(trigger); + }); + protected render() { return html` ${this.label ? html`` : nothing} diff --git a/src/data/automation.ts b/src/data/automation.ts index 10c193cd9d46..bb4d94177a92 100644 --- a/src/data/automation.ts +++ b/src/data/automation.ts @@ -75,14 +75,16 @@ export interface TriggerList { export interface BaseTrigger { alias?: string; - platform: string; + /** @deprecated Use `trigger` instead */ + platform?: string; + trigger: string; id?: string; variables?: Record; enabled?: boolean; } export interface StateTrigger extends BaseTrigger { - platform: "state"; + trigger: "state"; entity_id: string | string[]; attribute?: string; from?: string | string[]; @@ -91,25 +93,25 @@ export interface StateTrigger extends BaseTrigger { } export interface MqttTrigger extends BaseTrigger { - platform: "mqtt"; + trigger: "mqtt"; topic: string; payload?: string; } export interface GeoLocationTrigger extends BaseTrigger { - platform: "geo_location"; + trigger: "geo_location"; source: string; zone: string; event: "enter" | "leave"; } export interface HassTrigger extends BaseTrigger { - platform: "homeassistant"; + trigger: "homeassistant"; event: "start" | "shutdown"; } export interface NumericStateTrigger extends BaseTrigger { - platform: "numeric_state"; + trigger: "numeric_state"; entity_id: string | string[]; attribute?: string; above?: number; @@ -119,69 +121,69 @@ export interface NumericStateTrigger extends BaseTrigger { } export interface ConversationTrigger extends BaseTrigger { - platform: "conversation"; + trigger: "conversation"; command: string | string[]; } export interface SunTrigger extends BaseTrigger { - platform: "sun"; + trigger: "sun"; offset: number; event: "sunrise" | "sunset"; } export interface TimePatternTrigger extends BaseTrigger { - platform: "time_pattern"; + trigger: "time_pattern"; hours?: number | string; minutes?: number | string; seconds?: number | string; } export interface WebhookTrigger extends BaseTrigger { - platform: "webhook"; + trigger: "webhook"; webhook_id: string; allowed_methods?: string[]; local_only?: boolean; } export interface PersistentNotificationTrigger extends BaseTrigger { - platform: "persistent_notification"; + trigger: "persistent_notification"; notification_id?: string; update_type?: string[]; } export interface ZoneTrigger extends BaseTrigger { - platform: "zone"; + trigger: "zone"; entity_id: string; zone: string; event: "enter" | "leave"; } export interface TagTrigger extends BaseTrigger { - platform: "tag"; + trigger: "tag"; tag_id: string; device_id?: string; } export interface TimeTrigger extends BaseTrigger { - platform: "time"; + trigger: "time"; at: string; } export interface TemplateTrigger extends BaseTrigger { - platform: "template"; + trigger: "template"; value_template: string; for?: string | number | ForDict; } export interface EventTrigger extends BaseTrigger { - platform: "event"; + trigger: "event"; event_type: string; event_data?: any; context?: ContextConstraint; } export interface CalendarTrigger extends BaseTrigger { - platform: "calendar"; + trigger: "calendar"; event: "start" | "end"; entity_id: string; offset: string; @@ -379,10 +381,6 @@ export const normalizeAutomationConfig = < } } - if (config.actions) { - config.actions = migrateAutomationAction(config.actions); - } - return config; }; @@ -409,9 +407,35 @@ export const migrateAutomationConfig = < } delete config.action; } + + if (config.triggers) { + config.triggers = migrateAutomationTrigger(config.triggers); + } + + if (config.actions) { + config.actions = migrateAutomationAction(config.actions); + } + return config; }; +export const migrateAutomationTrigger = ( + trigger: Trigger | Trigger[] +): Trigger | Trigger[] => { + if (Array.isArray(trigger)) { + return trigger.map(migrateAutomationTrigger) as Trigger[]; + } + + if ("platform" in trigger) { + if (!("trigger" in trigger)) { + // @ts-ignore + trigger.trigger = trigger.platform; + } + delete trigger.platform; + } + return trigger; +}; + export const flattenTriggers = ( triggers: undefined | (Trigger | TriggerList)[] ): Trigger[] => { diff --git a/src/data/automation_i18n.ts b/src/data/automation_i18n.ts index 79be735048cd..474db8345c5b 100644 --- a/src/data/automation_i18n.ts +++ b/src/data/automation_i18n.ts @@ -103,7 +103,7 @@ const tryDescribeTrigger = ( } // Event Trigger - if (trigger.platform === "event" && trigger.event_type) { + if (trigger.trigger === "event" && trigger.event_type) { const eventTypes: string[] = []; if (Array.isArray(trigger.event_type)) { @@ -122,7 +122,7 @@ const tryDescribeTrigger = ( } // Home Assistant Trigger - if (trigger.platform === "homeassistant" && trigger.event) { + if (trigger.trigger === "homeassistant" && trigger.event) { return hass.localize( trigger.event === "start" ? `${triggerTranslationBaseKey}.homeassistant.description.started` @@ -131,7 +131,7 @@ const tryDescribeTrigger = ( } // Numeric State Trigger - if (trigger.platform === "numeric_state" && trigger.entity_id) { + if (trigger.trigger === "numeric_state" && trigger.entity_id) { const entities: string[] = []; const states = hass.states; @@ -206,7 +206,7 @@ const tryDescribeTrigger = ( } // State Trigger - if (trigger.platform === "state") { + if (trigger.trigger === "state") { const entities: string[] = []; const states = hass.states; @@ -329,7 +329,7 @@ const tryDescribeTrigger = ( } // Sun Trigger - if (trigger.platform === "sun" && trigger.event) { + if (trigger.trigger === "sun" && trigger.event) { let duration = ""; if (trigger.offset) { if (typeof trigger.offset === "number") { @@ -350,12 +350,12 @@ const tryDescribeTrigger = ( } // Tag Trigger - if (trigger.platform === "tag") { + if (trigger.trigger === "tag") { return hass.localize(`${triggerTranslationBaseKey}.tag.description.full`); } // Time Trigger - if (trigger.platform === "time" && trigger.at) { + if (trigger.trigger === "time" && trigger.at) { const result = ensureArray(trigger.at).map((at) => typeof at !== "string" ? at @@ -370,7 +370,7 @@ const tryDescribeTrigger = ( } // Time Pattern Trigger - if (trigger.platform === "time_pattern") { + if (trigger.trigger === "time_pattern") { if (!trigger.seconds && !trigger.minutes && !trigger.hours) { return hass.localize( `${triggerTranslationBaseKey}.time_pattern.description.initial` @@ -547,7 +547,7 @@ const tryDescribeTrigger = ( } // Zone Trigger - if (trigger.platform === "zone" && trigger.entity_id && trigger.zone) { + if (trigger.trigger === "zone" && trigger.entity_id && trigger.zone) { const entities: string[] = []; const zones: string[] = []; @@ -590,7 +590,7 @@ const tryDescribeTrigger = ( } // Geo Location Trigger - if (trigger.platform === "geo_location" && trigger.source && trigger.zone) { + if (trigger.trigger === "geo_location" && trigger.source && trigger.zone) { const sources: string[] = []; const zones: string[] = []; const states = hass.states; @@ -629,12 +629,12 @@ const tryDescribeTrigger = ( } // MQTT Trigger - if (trigger.platform === "mqtt") { + if (trigger.trigger === "mqtt") { return hass.localize(`${triggerTranslationBaseKey}.mqtt.description.full`); } // Template Trigger - if (trigger.platform === "template") { + if (trigger.trigger === "template") { let duration = ""; if (trigger.for) { duration = describeDuration(hass.locale, trigger.for) ?? ""; @@ -647,14 +647,14 @@ const tryDescribeTrigger = ( } // Webhook Trigger - if (trigger.platform === "webhook") { + if (trigger.trigger === "webhook") { return hass.localize( `${triggerTranslationBaseKey}.webhook.description.full` ); } // Conversation Trigger - if (trigger.platform === "conversation") { + if (trigger.trigger === "conversation") { if (!trigger.command) { return hass.localize( `${triggerTranslationBaseKey}.conversation.description.empty` @@ -673,14 +673,14 @@ const tryDescribeTrigger = ( } // Persistent Notification Trigger - if (trigger.platform === "persistent_notification") { + if (trigger.trigger === "persistent_notification") { return hass.localize( `${triggerTranslationBaseKey}.persistent_notification.description.full` ); } // Device Trigger - if (trigger.platform === "device" && trigger.device_id) { + if (trigger.trigger === "device" && trigger.device_id) { const config = trigger as DeviceTrigger; const localized = localizeDeviceAutomationTrigger( hass, @@ -698,7 +698,7 @@ const tryDescribeTrigger = ( return ( hass.localize( - `ui.panel.config.automation.editor.triggers.type.${trigger.platform}.label` + `ui.panel.config.automation.editor.triggers.type.${trigger.trigger}.label` ) || hass.localize(`ui.panel.config.automation.editor.triggers.unknown_trigger`) ); diff --git a/src/data/device_automation.ts b/src/data/device_automation.ts index b984ac9001fe..677e0a73ead2 100644 --- a/src/data/device_automation.ts +++ b/src/data/device_automation.ts @@ -1,7 +1,7 @@ import { computeStateName } from "../common/entity/compute_state_name"; import type { HaFormSchema } from "../components/ha-form/types"; import { HomeAssistant } from "../types"; -import { BaseTrigger } from "./automation"; +import { BaseTrigger, migrateAutomationTrigger } from "./automation"; import { computeEntityRegistryName, entityRegistryByEntityId, @@ -31,7 +31,7 @@ export interface DeviceCondition extends DeviceAutomation { export type DeviceTrigger = DeviceAutomation & BaseTrigger & { - platform: "device"; + trigger: "device"; }; export interface DeviceCapabilities { @@ -51,10 +51,12 @@ export const fetchDeviceConditions = (hass: HomeAssistant, deviceId: string) => }); export const fetchDeviceTriggers = (hass: HomeAssistant, deviceId: string) => - hass.callWS({ - type: "device_automation/trigger/list", - device_id: deviceId, - }); + hass + .callWS({ + type: "device_automation/trigger/list", + device_id: deviceId, + }) + .then((triggers) => migrateAutomationTrigger(triggers) as DeviceTrigger[]); export const fetchDeviceActionCapabilities = ( hass: HomeAssistant, @@ -91,7 +93,7 @@ const deviceAutomationIdentifiers = [ "subtype", "event", "condition", - "platform", + "trigger", ]; export const deviceAutomationsEqual = ( diff --git a/src/data/script.ts b/src/data/script.ts index 1e6c85a4582f..631882a7cb68 100644 --- a/src/data/script.ts +++ b/src/data/script.ts @@ -20,6 +20,7 @@ import { navigate } from "../common/navigate"; import { HomeAssistant } from "../types"; import { Condition, + migrateAutomationTrigger, ShorthandAndCondition, ShorthandNotCondition, ShorthandOrCondition, @@ -480,5 +481,10 @@ export const migrateAutomationAction = ( } } + if (actionType === "wait_for_trigger") { + const _action = action as WaitForTriggerAction; + migrateAutomationTrigger(_action.wait_for_trigger); + } + return action; }; diff --git a/src/panels/config/automation/action/ha-automation-action-row.ts b/src/panels/config/automation/action/ha-automation-action-row.ts index c31e5ccc8cc4..122c1d77dfda 100644 --- a/src/panels/config/automation/action/ha-automation-action-row.ts +++ b/src/panels/config/automation/action/ha-automation-action-row.ts @@ -55,6 +55,7 @@ import { Action, NonConditionAction, getActionType, + migrateAutomationAction, } from "../../../../data/script"; import { describeAction } from "../../../../data/script_i18n"; import { callExecuteScript } from "../../../../data/service"; @@ -73,10 +74,10 @@ import "./types/ha-automation-action-delay"; import "./types/ha-automation-action-device_id"; import "./types/ha-automation-action-event"; import "./types/ha-automation-action-if"; -import "./types/ha-automation-action-sequence"; import "./types/ha-automation-action-parallel"; import "./types/ha-automation-action-play_media"; import "./types/ha-automation-action-repeat"; +import "./types/ha-automation-action-sequence"; import "./types/ha-automation-action-service"; import "./types/ha-automation-action-set_conversation_response"; import "./types/ha-automation-action-stop"; @@ -564,7 +565,9 @@ export default class HaAutomationActionRow extends LitElement { if (!ev.detail.isValid) { return; } - fireEvent(this, "value-changed", { value: ev.detail.value }); + fireEvent(this, "value-changed", { + value: migrateAutomationAction(ev.detail.value), + }); } private _onUiChanged(ev: CustomEvent) { diff --git a/src/panels/config/automation/action/ha-automation-action.ts b/src/panels/config/automation/action/ha-automation-action.ts index 81a335265902..f3dc0257ce55 100644 --- a/src/panels/config/automation/action/ha-automation-action.ts +++ b/src/panels/config/automation/action/ha-automation-action.ts @@ -19,7 +19,7 @@ import "../../../../components/ha-sortable"; import "../../../../components/ha-svg-icon"; import { getService, isService } from "../../../../data/action"; import type { AutomationClipboard } from "../../../../data/automation"; -import { Action, migrateAutomationAction } from "../../../../data/script"; +import { Action } from "../../../../data/script"; import { HomeAssistant, ItemPath } from "../../../../types"; import { PASTE_VALUE, @@ -243,10 +243,7 @@ export default class HaAutomationAction extends LitElement { private _actionChanged(ev: CustomEvent) { ev.stopPropagation(); const actions = [...this.actions]; - const newValue = - ev.detail.value === null - ? ev.detail.value - : (migrateAutomationAction(ev.detail.value) as Action); + const newValue = ev.detail.value; const index = (ev.target as any).index; if (newValue === null) { diff --git a/src/panels/config/automation/ha-automation-editor.ts b/src/panels/config/automation/ha-automation-editor.ts index 61e3f6111933..43c9ca0e643e 100644 --- a/src/panels/config/automation/ha-automation-editor.ts +++ b/src/panels/config/automation/ha-automation-editor.ts @@ -46,12 +46,12 @@ import { fetchAutomationFileConfig, getAutomationEditorInitData, getAutomationStateConfig, - migrateAutomationConfig, normalizeAutomationConfig, saveAutomationConfig, showAutomationEditor, triggerAutomationActions, } from "../../../data/automation"; +import { substituteBlueprint } from "../../../data/blueprint"; import { validateConfig } from "../../../data/config"; import { UNAVAILABLE } from "../../../data/entity"; import { fetchEntityRegistry } from "../../../data/entity_registry"; @@ -69,7 +69,6 @@ import { showAutomationModeDialog } from "./automation-mode-dialog/show-dialog-a import { showAutomationRenameDialog } from "./automation-rename-dialog/show-dialog-automation-rename"; import "./blueprint-automation-editor"; import "./manual-automation-editor"; -import { substituteBlueprint } from "../../../data/blueprint"; declare global { interface HTMLElementTagNameMap { @@ -640,7 +639,7 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) { } this._config = { id: this._config?.id, - ...migrateAutomationConfig(ev.detail.value), + ...normalizeAutomationConfig(ev.detail.value), }; this._errors = undefined; this._dirty = true; diff --git a/src/panels/config/automation/structs.ts b/src/panels/config/automation/structs.ts index a8b988116620..ad2d14722f8c 100644 --- a/src/panels/config/automation/structs.ts +++ b/src/panels/config/automation/structs.ts @@ -1,7 +1,7 @@ import { object, optional, number, string, boolean } from "superstruct"; export const baseTriggerStruct = object({ - platform: string(), + trigger: string(), id: optional(string()), enabled: optional(boolean()), }); diff --git a/src/panels/config/automation/trigger/ha-automation-trigger-row.ts b/src/panels/config/automation/trigger/ha-automation-trigger-row.ts index 99eacf750c66..31e996fab0af 100644 --- a/src/panels/config/automation/trigger/ha-automation-trigger-row.ts +++ b/src/panels/config/automation/trigger/ha-automation-trigger-row.ts @@ -41,7 +41,11 @@ import "../../../../components/ha-icon-button"; import "../../../../components/ha-textfield"; import { HaYamlEditor } from "../../../../components/ha-yaml-editor"; import type { AutomationClipboard } from "../../../../data/automation"; -import { Trigger, subscribeTrigger } from "../../../../data/automation"; +import { + Trigger, + migrateAutomationTrigger, + subscribeTrigger, +} from "../../../../data/automation"; import { describeTrigger } from "../../../../data/automation_i18n"; import { validateConfig } from "../../../../data/config"; import { fullEntitiesContext } from "../../../../data/context"; @@ -71,6 +75,7 @@ import "./types/ha-automation-trigger-time"; import "./types/ha-automation-trigger-time_pattern"; import "./types/ha-automation-trigger-webhook"; import "./types/ha-automation-trigger-zone"; +import { preventDefault } from "../../../../common/dom/prevent_default"; export interface TriggerElement extends LitElement { trigger: Trigger; @@ -98,8 +103,6 @@ export const handleChangeEvent = (element: TriggerElement, ev: CustomEvent) => { fireEvent(element, "value-changed", { value: newTrigger }); }; -const preventDefault = (ev) => ev.preventDefault(); - @customElement("ha-automation-trigger-row") export default class HaAutomationTriggerRow extends LitElement { @property({ attribute: false }) public hass!: HomeAssistant; @@ -144,7 +147,7 @@ export default class HaAutomationTriggerRow extends LitElement { if (!this.trigger) return nothing; const supported = - customElements.get(`ha-automation-trigger-${this.trigger.platform}`) !== + customElements.get(`ha-automation-trigger-${this.trigger.trigger}`) !== undefined; const yamlMode = this._yamlMode || !supported; const showId = "id" in this.trigger || this._requestShowId; @@ -165,7 +168,7 @@ export default class HaAutomationTriggerRow extends LitElement {

${describeTrigger(this.trigger, this.hass, this._entityReg)}

@@ -333,7 +336,7 @@ export default class HaAutomationTriggerRow extends LitElement { ? html` ${this.hass.localize( "ui.panel.config.automation.editor.triggers.unsupported_platform", - { platform: this.trigger.platform } + { platform: this.trigger.trigger } )} ` : ""} @@ -363,7 +366,7 @@ export default class HaAutomationTriggerRow extends LitElement { @value-changed=${this._onUiChanged} > ${dynamicElement( - `ha-automation-trigger-${this.trigger.platform}`, + `ha-automation-trigger-${this.trigger.trigger}`, { hass: this.hass, trigger: this.trigger, @@ -574,7 +577,9 @@ export default class HaAutomationTriggerRow extends LitElement { return; } this._warnings = undefined; - fireEvent(this, "value-changed", { value: ev.detail.value }); + fireEvent(this, "value-changed", { + value: migrateAutomationTrigger(ev.detail.value), + }); } private _onUiChanged(ev: CustomEvent) { diff --git a/src/panels/config/automation/trigger/ha-automation-trigger.ts b/src/panels/config/automation/trigger/ha-automation-trigger.ts index 898b28fca3ec..39da68e02992 100644 --- a/src/panels/config/automation/trigger/ha-automation-trigger.ts +++ b/src/panels/config/automation/trigger/ha-automation-trigger.ts @@ -130,7 +130,7 @@ export default class HaAutomationTrigger extends LitElement { showAddAutomationElementDialog(this, { type: "trigger", add: this._addTrigger, - clipboardItem: this._clipboard?.trigger?.platform, + clipboardItem: this._clipboard?.trigger?.trigger, }); } @@ -139,9 +139,9 @@ export default class HaAutomationTrigger extends LitElement { if (value === PASTE_VALUE) { triggers = this.triggers.concat(deepClone(this._clipboard!.trigger)); } else { - const platform = value as Trigger["platform"]; + const trigger = value as Trigger["trigger"]; const elClass = customElements.get( - `ha-automation-trigger-${platform}` + `ha-automation-trigger-${trigger}` ) as CustomElementConstructor & { defaultConfig: Trigger; }; diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-calendar.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-calendar.ts index a1f7b2d54f91..4ece6655aea9 100644 --- a/src/panels/config/automation/trigger/types/ha-automation-trigger-calendar.ts +++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-calendar.ts @@ -71,7 +71,7 @@ export class HaCalendarTrigger extends LitElement implements TriggerElement { public static get defaultConfig(): CalendarTrigger { return { - platform: "calendar", + trigger: "calendar", entity_id: "", event: "start" as CalendarTrigger["event"], offset: "0", diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-conversation.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-conversation.ts index 7a7ba188fa21..c0fa1b0dd94f 100644 --- a/src/panels/config/automation/trigger/types/ha-automation-trigger-conversation.ts +++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-conversation.ts @@ -26,7 +26,7 @@ export class HaConversationTrigger @query("#option_input", true) private _optionInput?: HaTextField; public static get defaultConfig(): ConversationTrigger { - return { platform: "conversation", command: "" }; + return { trigger: "conversation", command: "" }; } protected render() { diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-device.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-device.ts index 660f43beb98f..e1b2153a83dc 100644 --- a/src/panels/config/automation/trigger/types/ha-automation-trigger-device.ts +++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-device.ts @@ -40,7 +40,7 @@ export class HaDeviceTrigger extends LitElement { public static get defaultConfig(): DeviceTrigger { return { - platform: "device", + trigger: "device", device_id: "", domain: "", entity_id: "", @@ -155,7 +155,7 @@ export class HaDeviceTrigger extends LitElement { this._deviceId = ev.target.value; if (this._deviceId === undefined) { fireEvent(this, "value-changed", { - value: { ...HaDeviceTrigger.defaultConfig, platform: "device" }, + value: { ...HaDeviceTrigger.defaultConfig, trigger: "device" }, }); } } diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-event.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-event.ts index 2685ff25f1d6..ae8f3405bfad 100644 --- a/src/panels/config/automation/trigger/types/ha-automation-trigger-event.ts +++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-event.ts @@ -20,7 +20,7 @@ export class HaEventTrigger extends LitElement implements TriggerElement { @property({ type: Boolean }) public disabled = false; public static get defaultConfig(): EventTrigger { - return { platform: "event", event_type: "" }; + return { trigger: "event", event_type: "" }; } protected render() { diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-geo_location.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-geo_location.ts index 38605caeed34..c613c03193d6 100644 --- a/src/panels/config/automation/trigger/types/ha-automation-trigger-geo_location.ts +++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-geo_location.ts @@ -45,7 +45,7 @@ export class HaGeolocationTrigger extends LitElement { public static get defaultConfig(): GeoLocationTrigger { return { - platform: "geo_location", + trigger: "geo_location", source: "", zone: "", event: "enter" as GeoLocationTrigger["event"], diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-homeassistant.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-homeassistant.ts index 94f241a93a36..f194a734e23b 100644 --- a/src/panels/config/automation/trigger/types/ha-automation-trigger-homeassistant.ts +++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-homeassistant.ts @@ -43,7 +43,7 @@ export class HaHassTrigger extends LitElement { public static get defaultConfig(): HassTrigger { return { - platform: "homeassistant", + trigger: "homeassistant", event: "start" as HassTrigger["event"], }; } diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-mqtt.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-mqtt.ts index 78a487488073..d5b917e8e693 100644 --- a/src/panels/config/automation/trigger/types/ha-automation-trigger-mqtt.ts +++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-mqtt.ts @@ -21,7 +21,7 @@ export class HaMQTTTrigger extends LitElement implements TriggerElement { @property({ type: Boolean }) public disabled = false; public static get defaultConfig(): MqttTrigger { - return { platform: "mqtt", topic: "" }; + return { trigger: "mqtt", topic: "" }; } protected render() { diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-numeric_state.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-numeric_state.ts index f7b812c511e5..80bef1cd663a 100644 --- a/src/panels/config/automation/trigger/types/ha-automation-trigger-numeric_state.ts +++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-numeric_state.ts @@ -239,7 +239,7 @@ export class HaNumericStateTrigger extends LitElement { public static get defaultConfig(): NumericStateTrigger { return { - platform: "numeric_state", + trigger: "numeric_state", entity_id: [], }; } diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-persistent_notification.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-persistent_notification.ts index f08ef50a09dc..b980c8ba44ef 100644 --- a/src/panels/config/automation/trigger/types/ha-automation-trigger-persistent_notification.ts +++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-persistent_notification.ts @@ -72,7 +72,7 @@ export class HaPersistentNotificationTrigger public static get defaultConfig(): PersistentNotificationTrigger { return { - platform: "persistent_notification", + trigger: "persistent_notification", update_type: [...DEFAULT_UPDATE_TYPES], notification_id: DEFAULT_NOTIFICATION_ID, }; diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-state.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-state.ts index 51f55030747f..a09d709bdc7f 100644 --- a/src/panels/config/automation/trigger/types/ha-automation-trigger-state.ts +++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-state.ts @@ -29,7 +29,7 @@ const stateTriggerStruct = assign( baseTriggerStruct, object({ alias: optional(string()), - platform: literal("state"), + trigger: literal("state"), entity_id: optional(union([string(), array(string())])), attribute: optional(string()), from: optional(nullable(string())), @@ -49,7 +49,7 @@ export class HaStateTrigger extends LitElement implements TriggerElement { @property({ type: Boolean }) public disabled = false; public static get defaultConfig(): StateTrigger { - return { platform: "state", entity_id: [] }; + return { trigger: "state", entity_id: [] }; } private _schema = memoizeOne( diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-sun.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-sun.ts index a60db83391dd..99171d893531 100644 --- a/src/panels/config/automation/trigger/types/ha-automation-trigger-sun.ts +++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-sun.ts @@ -45,7 +45,7 @@ export class HaSunTrigger extends LitElement implements TriggerElement { public static get defaultConfig(): SunTrigger { return { - platform: "sun", + trigger: "sun", event: "sunrise" as SunTrigger["event"], offset: 0, }; diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-tag.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-tag.ts index e7f82d8c7701..40dd13fc9184 100644 --- a/src/panels/config/automation/trigger/types/ha-automation-trigger-tag.ts +++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-tag.ts @@ -20,7 +20,7 @@ export class HaTagTrigger extends LitElement implements TriggerElement { @state() private _tags?: Tag[]; public static get defaultConfig(): TagTrigger { - return { platform: "tag", tag_id: "" }; + return { trigger: "tag", tag_id: "" }; } protected firstUpdated(changedProperties: PropertyValues) { diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-template.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-template.ts index a12464b22f6a..0e060108cec8 100644 --- a/src/panels/config/automation/trigger/types/ha-automation-trigger-template.ts +++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-template.ts @@ -23,7 +23,7 @@ export class HaTemplateTrigger extends LitElement { @property({ type: Boolean }) public disabled = false; public static get defaultConfig(): TemplateTrigger { - return { platform: "template", value_template: "" }; + return { trigger: "template", value_template: "" }; } public willUpdate(changedProperties: PropertyValues) { diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-time.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-time.ts index e7db9bba11ba..9009cb3217dd 100644 --- a/src/panels/config/automation/trigger/types/ha-automation-trigger-time.ts +++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-time.ts @@ -20,7 +20,7 @@ export class HaTimeTrigger extends LitElement implements TriggerElement { @state() private _inputMode?: boolean; public static get defaultConfig(): TimeTrigger { - return { platform: "time", at: "" }; + return { trigger: "time", at: "" }; } private _schema = memoizeOne( diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-time_pattern.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-time_pattern.ts index 9217495673aa..6f012c62f96d 100644 --- a/src/panels/config/automation/trigger/types/ha-automation-trigger-time_pattern.ts +++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-time_pattern.ts @@ -22,7 +22,7 @@ export class HaTimePatternTrigger extends LitElement implements TriggerElement { @property({ type: Boolean }) public disabled = false; public static get defaultConfig(): TimePatternTrigger { - return { platform: "time_pattern" }; + return { trigger: "time_pattern" }; } protected render() { diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-webhook.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-webhook.ts index 9adf5a05d536..5237a8eaeb8a 100644 --- a/src/panels/config/automation/trigger/types/ha-automation-trigger-webhook.ts +++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-webhook.ts @@ -38,7 +38,7 @@ export class HaWebhookTrigger extends LitElement { public static get defaultConfig(): WebhookTrigger { return { - platform: "webhook", + trigger: "webhook", allowed_methods: [...DEFAULT_METHODS], local_only: true, webhook_id: DEFAULT_WEBHOOK_ID, diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-zone.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-zone.ts index fa0676094de7..4730893ae962 100644 --- a/src/panels/config/automation/trigger/types/ha-automation-trigger-zone.ts +++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-zone.ts @@ -25,7 +25,7 @@ export class HaZoneTrigger extends LitElement { public static get defaultConfig(): ZoneTrigger { return { - platform: "zone", + trigger: "zone", entity_id: "", zone: "", event: "enter" as ZoneTrigger["event"], diff --git a/src/panels/config/tags/ha-config-tags.ts b/src/panels/config/tags/ha-config-tags.ts index 66eded944ca9..cf87bafa7d3d 100644 --- a/src/panels/config/tags/ha-config-tags.ts +++ b/src/panels/config/tags/ha-config-tags.ts @@ -213,7 +213,7 @@ export class HaConfigTags extends SubscribeMixin(LitElement) { alias: this.hass.localize("ui.panel.config.tag.automation_title", { name: tag.name || tag.id, }), - trigger: [{ platform: "tag", tag_id: tag.id } as TagTrigger], + trigger: [{ trigger: "tag", tag_id: tag.id } as TagTrigger], }; showAutomationEditor(data); };