Migrate trigger platform key to trigger (#22054)

* Migrate trigger platform key to trigger

* fix gallery configs

* Update ha-automation-editor.ts

* migrate device automation triggers
This commit is contained in:
Bram Kragten 2024-09-25 14:20:27 +02:00 committed by GitHub
parent 2793ca65cd
commit dc940f248c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
37 changed files with 167 additions and 120 deletions

View File

@ -219,7 +219,7 @@ export const basicTrace: DemoTrace = {
description: "",
triggers: [
{
platform: "state",
trigger: "state",
entity_id: "input_boolean.toggle_1",
},
],

View File

@ -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",

View File

@ -48,7 +48,7 @@ const ACTIONS = [
{
wait_for_trigger: [
{
platform: "state",
trigger: "state",
entity_id: "input_boolean.toggle_1",
},
],

View File

@ -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",
};

View File

@ -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"],
},
],

View File

@ -26,7 +26,7 @@ class HaDeviceTriggerPicker extends HaDeviceAutomationPicker<DeviceTrigger> {
fetchDeviceTriggers,
(deviceId?: string) => ({
device_id: deviceId || "",
platform: "device",
trigger: "device",
domain: "",
entity_id: "",
})

View File

@ -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`<label>${this.label}</label>` : nothing}
<ha-automation-action
.disabled=${this.disabled}
.actions=${this.value || []}
.actions=${this._actions(this.value)}
.hass=${this.hass}
.path=${this.selector.action?.path}
></ha-automation-action>

View File

@ -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 {

View File

@ -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`<label>${this.label}</label>` : nothing}
<ha-automation-trigger
.disabled=${this.disabled}
.triggers=${this.value || []}
.triggers=${this._triggers(this.value)}
.hass=${this.hass}
.path=${this.selector.trigger?.path}
></ha-automation-trigger>

View File

@ -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<string, unknown>;
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 | (Trigger | TriggerList)[]
): Trigger[] => {

View File

@ -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`)
);

View File

@ -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<DeviceTrigger[]>({
type: "device_automation/trigger/list",
device_id: deviceId,
});
hass
.callWS<DeviceTrigger[]>({
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 = (

View File

@ -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;
};

View File

@ -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) {

View File

@ -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) {

View File

@ -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;

View File

@ -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()),
});

View File

@ -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 {
<h3 slot="header">
<ha-svg-icon
class="trigger-icon"
.path=${TRIGGER_ICONS[this.trigger.platform]}
.path=${TRIGGER_ICONS[this.trigger.trigger]}
></ha-svg-icon>
${describeTrigger(this.trigger, this.hass, this._entityReg)}
</h3>
@ -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) {

View File

@ -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;
};

View File

@ -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",

View File

@ -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() {

View File

@ -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" },
});
}
}

View File

@ -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() {

View File

@ -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"],

View File

@ -43,7 +43,7 @@ export class HaHassTrigger extends LitElement {
public static get defaultConfig(): HassTrigger {
return {
platform: "homeassistant",
trigger: "homeassistant",
event: "start" as HassTrigger["event"],
};
}

View File

@ -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() {

View File

@ -239,7 +239,7 @@ export class HaNumericStateTrigger extends LitElement {
public static get defaultConfig(): NumericStateTrigger {
return {
platform: "numeric_state",
trigger: "numeric_state",
entity_id: [],
};
}

View File

@ -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,
};

View File

@ -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(

View File

@ -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,
};

View File

@ -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) {

View File

@ -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) {

View File

@ -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(

View File

@ -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() {

View File

@ -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,

View File

@ -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"],

View File

@ -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);
};