From 1407e4158c8c6546a057506e553be12aa9f5c769 Mon Sep 17 00:00:00 2001 From: Zack Date: Thu, 10 Feb 2022 11:55:51 -0600 Subject: [PATCH 1/8] Convert --- .../types/ha-automation-trigger-mqtt.ts | 50 +++++++++++-------- 1 file changed, 28 insertions(+), 22 deletions(-) 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 e3e997771f54..540892bb6278 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 @@ -1,12 +1,15 @@ -import "@polymer/paper-input/paper-input"; import { html, LitElement } from "lit"; import { customElement, property } from "lit/decorators"; +import { fireEvent } from "../../../../../common/dom/fire_event"; +import { HaFormSchema } from "../../../../../components/ha-form/types"; import { MqttTrigger } from "../../../../../data/automation"; import { HomeAssistant } from "../../../../../types"; -import { - handleChangeEvent, - TriggerElement, -} from "../ha-automation-trigger-row"; +import { TriggerElement } from "../ha-automation-trigger-row"; + +const SCHEMA = [ + { name: "topic", selector: { text: {} } }, + { name: "payload", required: false, selector: { text: {} } }, +]; @customElement("ha-automation-trigger-mqtt") export class HaMQTTTrigger extends LitElement implements TriggerElement { @@ -19,29 +22,32 @@ export class HaMQTTTrigger extends LitElement implements TriggerElement { } protected render() { - const { topic, payload } = this.trigger; return html` - - + > `; } private _valueChanged(ev: CustomEvent): void { - handleChangeEvent(this, ev); + ev.stopPropagation(); + const newTrigger = ev.detail.value; + Object.keys(newTrigger).forEach((key) => + newTrigger[key] === undefined || newTrigger[key] === "" + ? delete newTrigger[key] + : {} + ); + fireEvent(this, "value-changed", { value: newTrigger }); + } + + private _computeLabelCallback(schema: HaFormSchema): string { + return this.hass.localize( + `ui.panel.config.automation.editor.triggers.type.mqtt.${schema.name}` + ); } } From 9586ffddc27968b3219d0433c440edcd390788c7 Mon Sep 17 00:00:00 2001 From: Zack Date: Thu, 10 Feb 2022 13:03:45 -0600 Subject: [PATCH 2/8] type --- .../automation/trigger/types/ha-automation-trigger-mqtt.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 540892bb6278..72478cf34472 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 @@ -6,7 +6,7 @@ import { MqttTrigger } from "../../../../../data/automation"; import { HomeAssistant } from "../../../../../types"; import { TriggerElement } from "../ha-automation-trigger-row"; -const SCHEMA = [ +const SCHEMA: HaFormSchema[] = [ { name: "topic", selector: { text: {} } }, { name: "payload", required: false, selector: { text: {} } }, ]; From a2e383385424d701183c787fca3985af2b25a857 Mon Sep 17 00:00:00 2001 From: Zack Date: Thu, 10 Feb 2022 13:43:05 -0600 Subject: [PATCH 3/8] Update Value Changed --- .../automation/trigger/types/ha-automation-trigger-mqtt.ts | 5 ----- 1 file changed, 5 deletions(-) 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 72478cf34472..31cdd96f50bc 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 @@ -36,11 +36,6 @@ export class HaMQTTTrigger extends LitElement implements TriggerElement { private _valueChanged(ev: CustomEvent): void { ev.stopPropagation(); const newTrigger = ev.detail.value; - Object.keys(newTrigger).forEach((key) => - newTrigger[key] === undefined || newTrigger[key] === "" - ? delete newTrigger[key] - : {} - ); fireEvent(this, "value-changed", { value: newTrigger }); } From 1bd863df958b12c6575845a64c624c62212254b3 Mon Sep 17 00:00:00 2001 From: Zack Date: Thu, 10 Feb 2022 15:23:38 -0600 Subject: [PATCH 4/8] Fix Requires --- .../automation/trigger/types/ha-automation-trigger-mqtt.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 31cdd96f50bc..6facd41c5772 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 @@ -7,8 +7,8 @@ import { HomeAssistant } from "../../../../../types"; import { TriggerElement } from "../ha-automation-trigger-row"; const SCHEMA: HaFormSchema[] = [ - { name: "topic", selector: { text: {} } }, - { name: "payload", required: false, selector: { text: {} } }, + { name: "topic", required: true, selector: { text: {} } }, + { name: "payload", selector: { text: {} } }, ]; @customElement("ha-automation-trigger-mqtt") From b6e7b78592139742a3df2a0750e370aff993e5b9 Mon Sep 17 00:00:00 2001 From: Zack Date: Thu, 10 Feb 2022 15:28:03 -0600 Subject: [PATCH 5/8] review --- .../automation/trigger/types/ha-automation-trigger-mqtt.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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 6facd41c5772..165d163621d4 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 @@ -39,11 +39,9 @@ export class HaMQTTTrigger extends LitElement implements TriggerElement { fireEvent(this, "value-changed", { value: newTrigger }); } - private _computeLabelCallback(schema: HaFormSchema): string { - return this.hass.localize( + private _computeLabelCallback = (schema: HaFormSchema): string => this.hass.localize( `ui.panel.config.automation.editor.triggers.type.mqtt.${schema.name}` ); - } } declare global { From 4d1a0363d72d86b7f79d2440cdbf317261f99c3b Mon Sep 17 00:00:00 2001 From: Zack Barett Date: Thu, 10 Feb 2022 15:33:40 -0600 Subject: [PATCH 6/8] Update src/panels/config/automation/trigger/types/ha-automation-trigger-mqtt.ts Co-authored-by: Paulus Schoutsen --- .../automation/trigger/types/ha-automation-trigger-mqtt.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 165d163621d4..ae4730232195 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 @@ -4,7 +4,7 @@ import { fireEvent } from "../../../../../common/dom/fire_event"; import { HaFormSchema } from "../../../../../components/ha-form/types"; import { MqttTrigger } from "../../../../../data/automation"; import { HomeAssistant } from "../../../../../types"; -import { TriggerElement } from "../ha-automation-trigger-row"; +import type { TriggerElement } from "../ha-automation-trigger-row"; const SCHEMA: HaFormSchema[] = [ { name: "topic", required: true, selector: { text: {} } }, From 12fffd3cfe5b5489ce0b086220dc8628b4309d80 Mon Sep 17 00:00:00 2001 From: Zack Barett Date: Thu, 10 Feb 2022 15:33:45 -0600 Subject: [PATCH 7/8] Update src/panels/config/automation/trigger/types/ha-automation-trigger-mqtt.ts Co-authored-by: Paulus Schoutsen --- .../automation/trigger/types/ha-automation-trigger-mqtt.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ae4730232195..f9afa922664f 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 @@ -1,7 +1,7 @@ import { html, LitElement } from "lit"; import { customElement, property } from "lit/decorators"; import { fireEvent } from "../../../../../common/dom/fire_event"; -import { HaFormSchema } from "../../../../../components/ha-form/types"; +import type { HaFormSchema } from "../../../../../components/ha-form/types"; import { MqttTrigger } from "../../../../../data/automation"; import { HomeAssistant } from "../../../../../types"; import type { TriggerElement } from "../ha-automation-trigger-row"; From 45540ff44c3facdd2973468c7ded06436158c611 Mon Sep 17 00:00:00 2001 From: Zack Date: Thu, 10 Feb 2022 15:34:00 -0600 Subject: [PATCH 8/8] prettier --- .../automation/trigger/types/ha-automation-trigger-mqtt.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 f9afa922664f..95941c85b27f 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 @@ -39,7 +39,8 @@ export class HaMQTTTrigger extends LitElement implements TriggerElement { fireEvent(this, "value-changed", { value: newTrigger }); } - private _computeLabelCallback = (schema: HaFormSchema): string => this.hass.localize( + private _computeLabelCallback = (schema: HaFormSchema): string => + this.hass.localize( `ui.panel.config.automation.editor.triggers.type.mqtt.${schema.name}` ); }