mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-19 15:26:36 +00:00
MQTT Trigger to Ha-Form (#11643)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
parent
ce9f83e9a2
commit
ac90bb7088
@ -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 type { HaFormSchema } from "../../../../../components/ha-form/types";
|
||||
import { MqttTrigger } from "../../../../../data/automation";
|
||||
import { HomeAssistant } from "../../../../../types";
|
||||
import {
|
||||
handleChangeEvent,
|
||||
TriggerElement,
|
||||
} from "../ha-automation-trigger-row";
|
||||
import type { TriggerElement } from "../ha-automation-trigger-row";
|
||||
|
||||
const SCHEMA: HaFormSchema[] = [
|
||||
{ name: "topic", required: true, selector: { text: {} } },
|
||||
{ name: "payload", selector: { text: {} } },
|
||||
];
|
||||
|
||||
@customElement("ha-automation-trigger-mqtt")
|
||||
export class HaMQTTTrigger extends LitElement implements TriggerElement {
|
||||
@ -19,30 +22,27 @@ export class HaMQTTTrigger extends LitElement implements TriggerElement {
|
||||
}
|
||||
|
||||
protected render() {
|
||||
const { topic, payload } = this.trigger;
|
||||
return html`
|
||||
<paper-input
|
||||
.label=${this.hass.localize(
|
||||
"ui.panel.config.automation.editor.triggers.type.mqtt.topic"
|
||||
)}
|
||||
name="topic"
|
||||
.value=${topic}
|
||||
<ha-form
|
||||
.schema=${SCHEMA}
|
||||
.data=${this.trigger}
|
||||
.hass=${this.hass}
|
||||
.computeLabel=${this._computeLabelCallback}
|
||||
@value-changed=${this._valueChanged}
|
||||
></paper-input>
|
||||
<paper-input
|
||||
.label=${this.hass.localize(
|
||||
"ui.panel.config.automation.editor.triggers.type.mqtt.payload"
|
||||
)}
|
||||
name="payload"
|
||||
.value=${payload}
|
||||
@value-changed=${this._valueChanged}
|
||||
></paper-input>
|
||||
></ha-form>
|
||||
`;
|
||||
}
|
||||
|
||||
private _valueChanged(ev: CustomEvent): void {
|
||||
handleChangeEvent(this, ev);
|
||||
ev.stopPropagation();
|
||||
const newTrigger = ev.detail.value;
|
||||
fireEvent(this, "value-changed", { value: newTrigger });
|
||||
}
|
||||
|
||||
private _computeLabelCallback = (schema: HaFormSchema): string =>
|
||||
this.hass.localize(
|
||||
`ui.panel.config.automation.editor.triggers.type.mqtt.${schema.name}`
|
||||
);
|
||||
}
|
||||
|
||||
declare global {
|
||||
|
Loading…
x
Reference in New Issue
Block a user