Time Pattern to HA Form (#11648)

This commit is contained in:
Zack Barett 2022-02-10 16:11:29 -06:00 committed by GitHub
parent fca7d2c5b0
commit ce9f83e9a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,12 +1,16 @@
import "@polymer/paper-input/paper-input";
import { html, LitElement } from "lit"; import { html, LitElement } from "lit";
import { customElement, property } from "lit/decorators"; import { customElement, property } from "lit/decorators";
import { TimePatternTrigger } from "../../../../../data/automation"; import { fireEvent } from "../../../../../common/dom/fire_event";
import { HomeAssistant } from "../../../../../types"; import type { HaFormSchema } from "../../../../../components/ha-form/types";
import { import type { TimePatternTrigger } from "../../../../../data/automation";
handleChangeEvent, import type { HomeAssistant } from "../../../../../types";
TriggerElement, import type { TriggerElement } from "../ha-automation-trigger-row";
} from "../ha-automation-trigger-row";
const SCHEMA: HaFormSchema[] = [
{ name: "hours", selector: { text: {} } },
{ name: "minutes", selector: { text: {} } },
{ name: "seconds", selector: { text: {} } },
];
@customElement("ha-automation-trigger-time_pattern") @customElement("ha-automation-trigger-time_pattern")
export class HaTimePatternTrigger extends LitElement implements TriggerElement { export class HaTimePatternTrigger extends LitElement implements TriggerElement {
@ -19,38 +23,27 @@ export class HaTimePatternTrigger extends LitElement implements TriggerElement {
} }
protected render() { protected render() {
const { hours, minutes, seconds } = this.trigger;
return html` return html`
<paper-input <ha-form
.label=${this.hass.localize( .hass=${this.hass}
"ui.panel.config.automation.editor.triggers.type.time_pattern.hours" .schema=${SCHEMA}
)} .data=${this.trigger}
name="hours" .computeLabel=${this._computeLabelCallback}
.value=${hours}
@value-changed=${this._valueChanged} @value-changed=${this._valueChanged}
></paper-input> ></ha-form>
<paper-input
.label=${this.hass.localize(
"ui.panel.config.automation.editor.triggers.type.time_pattern.minutes"
)}
name="minutes"
.value=${minutes}
@value-changed=${this._valueChanged}
></paper-input>
<paper-input
.label=${this.hass.localize(
"ui.panel.config.automation.editor.triggers.type.time_pattern.seconds"
)}
name="seconds"
.value=${seconds}
@value-changed=${this._valueChanged}
></paper-input>
`; `;
} }
private _valueChanged(ev: CustomEvent): void { 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.time_pattern.${schema.name}`
);
} }
declare global { declare global {