From cb568d005e8f2b635475dafc373798153e82ba5c Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Fri, 29 Dec 2023 18:59:11 +0100 Subject: [PATCH] dont allow UI editor when templates are used in repeat (#19188) --- .../types/ha-automation-action-repeat.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/panels/config/automation/action/types/ha-automation-action-repeat.ts b/src/panels/config/automation/action/types/ha-automation-action-repeat.ts index 890133d250..becc0f6f75 100644 --- a/src/panels/config/automation/action/types/ha-automation-action-repeat.ts +++ b/src/panels/config/automation/action/types/ha-automation-action-repeat.ts @@ -1,4 +1,4 @@ -import { css, CSSResultGroup, html, LitElement } from "lit"; +import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit"; import { customElement, property } from "lit/decorators"; import memoizeOne from "memoize-one"; import { fireEvent } from "../../../../../common/dom/fire_event"; @@ -12,6 +12,7 @@ import type { ActionElement } from "../ha-automation-action-row"; import type { LocalizeFunc } from "../../../../../common/translations/localize"; import "../../../../../components/ha-form/ha-form"; import type { SchemaUnion } from "../../../../../components/ha-form/types"; +import { hasTemplate } from "../../../../../common/string/has-template"; const OPTIONS = ["count", "while", "until", "for_each"] as const; @@ -31,6 +32,20 @@ export class HaRepeatAction extends LitElement implements ActionElement { return { repeat: { count: 2, sequence: [] } }; } + public willUpdate(changedProperties: PropertyValues) { + if (!changedProperties.has("action")) { + return; + } + // Check for templates in action. If found, revert to YAML mode. + if (this.action && hasTemplate(this.action)) { + fireEvent( + this, + "ui-mode-not-available", + Error(this.hass.localize("ui.errors.config.no_template_editor_support")) + ); + } + } + private _schema = memoizeOne( (localize: LocalizeFunc, type: string, reOrderMode: boolean) => [ @@ -92,7 +107,7 @@ export class HaRepeatAction extends LitElement implements ActionElement { this.reOrderMode ); const data = { ...action, type }; - return html`