Add jinja2 editor to template triggers/conditions (#12365)

Co-authored-by: Zack <zackbarett@hey.com>
This commit is contained in:
Franck Nijhof 2022-04-22 03:42:28 +02:00 committed by GitHub
parent 2099259393
commit 6865791596
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 27 deletions

View File

@ -1,6 +1,6 @@
import "../../../../../components/ha-textarea";
import { css, html, LitElement } from "lit";
import { html, LitElement } from "lit";
import { customElement, property } from "lit/decorators";
import "../../../../../components/ha-textarea";
import type { TemplateCondition } from "../../../../../data/automation";
import type { HomeAssistant } from "../../../../../types";
import { handleChangeEvent } from "../ha-automation-condition-row";
@ -18,28 +18,27 @@ export class HaTemplateCondition extends LitElement {
protected render() {
const { value_template } = this.condition;
return html`
<ha-textarea
name="value_template"
.label=${this.hass.localize(
<p>
${this.hass.localize(
"ui.panel.config.automation.editor.conditions.type.template.value_template"
)}
*
</p>
<ha-code-editor
.name=${"value_template"}
mode="jinja2"
.hass=${this.hass}
.value=${value_template}
@input=${this._valueChanged}
autocomplete-entities
@value-changed=${this._valueChanged}
dir="ltr"
autogrow
></ha-textarea>
></ha-code-editor>
`;
}
private _valueChanged(ev: CustomEvent): void {
handleChangeEvent(this, ev);
}
static styles = css`
ha-textarea {
display: block;
}
`;
}
declare global {

View File

@ -1,5 +1,5 @@
import "../../../../../components/ha-textarea";
import { css, html, LitElement } from "lit";
import { html, LitElement } from "lit";
import { customElement, property } from "lit/decorators";
import type { TemplateTrigger } from "../../../../../data/automation";
import type { HomeAssistant } from "../../../../../types";
@ -18,28 +18,27 @@ export class HaTemplateTrigger extends LitElement {
protected render() {
const { value_template } = this.trigger;
return html`
<ha-textarea
name="value_template"
.label=${this.hass.localize(
<p>
${this.hass.localize(
"ui.panel.config.automation.editor.triggers.type.template.value_template"
)}
*
</p>
<ha-code-editor
.name=${"value_template"}
mode="jinja2"
.hass=${this.hass}
.value=${value_template}
@input=${this._valueChanged}
autocomplete-entities
@value-changed=${this._valueChanged}
dir="ltr"
autogrow
></ha-textarea>
></ha-code-editor>
`;
}
private _valueChanged(ev: CustomEvent): void {
handleChangeEvent(this, ev);
}
static styles = css`
ha-textarea {
display: block;
}
`;
}
declare global {