Skip to content

Commit 5c3ccbf

Browse files
authored
Remove hard coded mqtt trigger, and migrate to new format (#28143)
1 parent 9710142 commit 5c3ccbf

File tree

6 files changed

+41
-72
lines changed

6 files changed

+41
-72
lines changed

gallery/src/pages/automation/editor-trigger.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { HaEventTrigger } from "../../../../src/panels/config/automation/trigger
1818
import { HaGeolocationTrigger } from "../../../../src/panels/config/automation/trigger/types/ha-automation-trigger-geo_location";
1919
import { HaHassTrigger } from "../../../../src/panels/config/automation/trigger/types/ha-automation-trigger-homeassistant";
2020
import { 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";
2221
import { HaNumericStateTrigger } from "../../../../src/panels/config/automation/trigger/types/ha-automation-trigger-numeric_state";
2322
import { HaPersistentNotificationTrigger } from "../../../../src/panels/config/automation/trigger/types/ha-automation-trigger-persistent_notification";
2423
import { 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 }],

src/data/automation.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff 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-
123117
export 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+
130130
export interface HassTrigger extends BaseTrigger {
131131
trigger: "homeassistant";
132132
event: "start" | "shutdown";

src/data/trigger.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff 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: {},

src/panels/config/automation/trigger/ha-automation-trigger-row.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ import "./types/ha-automation-trigger-event";
7272
import "./types/ha-automation-trigger-geo_location";
7373
import "./types/ha-automation-trigger-homeassistant";
7474
import "./types/ha-automation-trigger-list";
75-
import "./types/ha-automation-trigger-mqtt";
7675
import "./types/ha-automation-trigger-numeric_state";
7776
import "./types/ha-automation-trigger-persistent_notification";
7877
import "./types/ha-automation-trigger-platform";

src/panels/config/automation/trigger/types/ha-automation-trigger-mqtt.ts

Lines changed: 0 additions & 58 deletions
This file was deleted.

src/panels/config/automation/trigger/types/ha-automation-trigger-platform.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff 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")
2939
export 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"];

0 commit comments

Comments
 (0)