From edbfc22bf896d7c9fb93a8bb7e8f828f2f10c03f Mon Sep 17 00:00:00 2001 From: karwosts <32912880+karwosts@users.noreply.github.com> Date: Fri, 2 Aug 2024 03:30:09 -0700 Subject: [PATCH] Add a warning for improper usage of the template selector (#21545) * Add a warning when adding template yaml in the template selector * refinement --- .../ha-selector/ha-selector-template.ts | 42 +++++++++++++++++-- src/translations/en.json | 4 ++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/components/ha-selector/ha-selector-template.ts b/src/components/ha-selector/ha-selector-template.ts index 470f0b640a..3ecccf02c5 100644 --- a/src/components/ha-selector/ha-selector-template.ts +++ b/src/components/ha-selector/ha-selector-template.ts @@ -1,9 +1,18 @@ -import { css, html, LitElement } from "lit"; -import { customElement, property } from "lit/decorators"; +import { css, html, nothing, LitElement } from "lit"; +import { customElement, property, state } from "lit/decorators"; import { fireEvent } from "../../common/dom/fire_event"; import { HomeAssistant } from "../../types"; +import { documentationUrl } from "../../util/documentation-url"; import "../ha-code-editor"; import "../ha-input-helper-text"; +import "../ha-alert"; + +const WARNING_STRINGS = [ + "template:", + "sensor:", + "state:", + "platform: template", +]; @customElement("ha-selector-template") export class HaTemplateSelector extends LitElement { @@ -19,9 +28,33 @@ export class HaTemplateSelector extends LitElement { @property({ type: Boolean }) public required = true; + @state() private warn: string | undefined = undefined; + protected render() { return html` - ${this.label ? html`
${this.label}${this.required ? "*" : ""}
` : ""} + ${this.warn + ? html`${this.label}${this.required ? "*" : ""}
` + : nothing}