File tree Expand file tree Collapse file tree 6 files changed +41
-72
lines changed
gallery/src/pages/automation
panels/config/automation/trigger Expand file tree Collapse file tree 6 files changed +41
-72
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,6 @@ import { HaEventTrigger } from "../../../../src/panels/config/automation/trigger
1818import { HaGeolocationTrigger } from "../../../../src/panels/config/automation/trigger/types/ha-automation-trigger-geo_location" ;
1919import { HaHassTrigger } from "../../../../src/panels/config/automation/trigger/types/ha-automation-trigger-homeassistant" ;
2020import { HaTriggerList } from "../../../../src/panels/config/automation/trigger/types/ha-automation-trigger-list" ;
21- import { HaMQTTTrigger } from "../../../../src/panels/config/automation/trigger/types/ha-automation-trigger-mqtt" ;
2221import { HaNumericStateTrigger } from "../../../../src/panels/config/automation/trigger/types/ha-automation-trigger-numeric_state" ;
2322import { HaPersistentNotificationTrigger } from "../../../../src/panels/config/automation/trigger/types/ha-automation-trigger-persistent_notification" ;
2423import { HaStateTrigger } from "../../../../src/panels/config/automation/trigger/types/ha-automation-trigger-state" ;
@@ -38,11 +37,6 @@ const SCHEMAS: { name: string; triggers: Trigger[] }[] = [
3837 triggers : [ { ...HaStateTrigger . defaultConfig } ] ,
3938 } ,
4039
41- {
42- name : "MQTT" ,
43- triggers : [ { ...HaMQTTTrigger . defaultConfig } ] ,
44- } ,
45-
4640 {
4741 name : "GeoLocation" ,
4842 triggers : [ { ...HaGeolocationTrigger . defaultConfig } ] ,
Original file line number Diff line number Diff line change @@ -114,19 +114,19 @@ export interface StateTrigger extends BaseTrigger {
114114 for ?: string | number | ForDict ;
115115}
116116
117- export interface MqttTrigger extends BaseTrigger {
118- trigger : "mqtt" ;
119- topic : string ;
120- payload ?: string ;
121- }
122-
123117export interface GeoLocationTrigger extends BaseTrigger {
124118 trigger : "geo_location" ;
125119 source : string ;
126120 zone : string ;
127121 event : "enter" | "leave" ;
128122}
129123
124+ export interface MqttTrigger extends BaseTrigger {
125+ trigger : "mqtt" ;
126+ topic : string ;
127+ payload ?: string ;
128+ }
129+
130130export interface HassTrigger extends BaseTrigger {
131131 trigger : "homeassistant" ;
132132 event : "start" | "shutdown" ;
Original file line number Diff line number Diff line change @@ -40,7 +40,6 @@ export const TRIGGER_COLLECTIONS: AutomationElementGroupCollection[] = [
4040 event : { } ,
4141 geo_location : { } ,
4242 homeassistant : { } ,
43- mqtt : { } ,
4443 conversation : { } ,
4544 tag : { } ,
4645 template : { } ,
Original file line number Diff line number Diff line change @@ -72,7 +72,6 @@ import "./types/ha-automation-trigger-event";
7272import "./types/ha-automation-trigger-geo_location" ;
7373import "./types/ha-automation-trigger-homeassistant" ;
7474import "./types/ha-automation-trigger-list" ;
75- import "./types/ha-automation-trigger-mqtt" ;
7675import "./types/ha-automation-trigger-numeric_state" ;
7776import "./types/ha-automation-trigger-persistent_notification" ;
7877import "./types/ha-automation-trigger-platform" ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -25,6 +25,16 @@ const showOptionalToggle = (field: TriggerDescription["fields"][string]) =>
2525 ! field . required &&
2626 ! ( "boolean" in field . selector && field . default ) ;
2727
28+ const DEFAULT_KEYS : ( keyof PlatformTrigger ) [ ] = [
29+ "trigger" ,
30+ "target" ,
31+ "alias" ,
32+ "id" ,
33+ "variables" ,
34+ "enabled" ,
35+ "options" ,
36+ ] as const ;
37+
2838@customElement ( "ha-automation-trigger-platform" )
2939export class HaPlatformTrigger extends LitElement {
3040 @property ( { attribute : false } ) public hass ! : HomeAssistant ;
@@ -52,6 +62,31 @@ export class HaPlatformTrigger extends LitElement {
5262 if ( ! changedProperties . has ( "trigger" ) ) {
5363 return ;
5464 }
65+
66+ let newValue : PlatformTrigger | undefined ;
67+
68+ for ( const key in this . trigger ) {
69+ // Migrate old options to `options`
70+ if ( DEFAULT_KEYS . includes ( key as keyof PlatformTrigger ) ) {
71+ continue ;
72+ }
73+ if ( newValue === undefined ) {
74+ newValue = {
75+ ...this . trigger ,
76+ options : { [ key ] : this . trigger [ key ] } ,
77+ } ;
78+ } else {
79+ newValue . options ! [ key ] = this . trigger [ key ] ;
80+ }
81+ delete newValue [ key ] ;
82+ }
83+ if ( newValue !== undefined ) {
84+ fireEvent ( this , "value-changed" , {
85+ value : newValue ,
86+ } ) ;
87+ this . trigger = newValue ;
88+ }
89+
5590 const oldValue = changedProperties . get ( "trigger" ) as
5691 | undefined
5792 | this[ "trigger" ] ;
You can’t perform that action at this time.
0 commit comments