From 85b24afc108b696a4f8172276cf89772da29505d Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Tue, 29 Oct 2024 15:11:16 +0100 Subject: [PATCH] WIP: use template selector per field --- src/components/ha-service-control.ts | 52 ++++++++++++------- .../action/developer-tools-action.ts | 2 +- src/panels/lovelace/common/handle-action.ts | 14 +++-- 3 files changed, 41 insertions(+), 27 deletions(-) diff --git a/src/components/ha-service-control.ts b/src/components/ha-service-control.ts index 32f25e7024..24b390cc17 100644 --- a/src/components/ha-service-control.ts +++ b/src/components/ha-service-control.ts @@ -34,6 +34,7 @@ import { expandLabelTarget, Selector, TargetSelector, + TemplateSelector, } from "../data/selector"; import { HomeAssistant, ValueChangedEvent } from "../types"; import { documentationUrl } from "../util/documentation-url"; @@ -45,6 +46,7 @@ import "./ha-settings-row"; import "./ha-yaml-editor"; import type { HaYamlEditor } from "./ha-yaml-editor"; import "./ha-service-section-icon"; +import { hasTemplate } from "../common/string/has-template"; const attributeFilter = (values: any[], attribute: any) => { if (typeof attribute === "object") { @@ -79,6 +81,8 @@ interface ExtHassService extends Omit { hasSelector: string[]; } +const TEMPLATE_SELECTOR: TemplateSelector = { template: {} }; + @customElement("ha-service-control") export class HaServiceControl extends LitElement { @property({ attribute: false }) public hass!: HomeAssistant; @@ -478,7 +482,8 @@ export class HaServiceControl extends LitElement { >${this.hass.localize( "ui.components.service-control.target_secondary" )} + - + ${hasTemplate(this._value?.data?.[dataField.key]) + ? html` + + ` + : html` + + `} ` : ""; }; diff --git a/src/panels/developer-tools/action/developer-tools-action.ts b/src/panels/developer-tools/action/developer-tools-action.ts index 23129a3c18..9f548f38c6 100644 --- a/src/panels/developer-tools/action/developer-tools-action.ts +++ b/src/panels/developer-tools/action/developer-tools-action.ts @@ -529,7 +529,7 @@ class HaPanelDevAction extends LitElement { ) { return false; } - return hasTemplate(val); + return false; }))) ) { this._yamlMode = true; diff --git a/src/panels/lovelace/common/handle-action.ts b/src/panels/lovelace/common/handle-action.ts index 3c51b0d468..f0cebc7098 100644 --- a/src/panels/lovelace/common/handle-action.ts +++ b/src/panels/lovelace/common/handle-action.ts @@ -3,6 +3,7 @@ import { navigate } from "../../../common/navigate"; import { forwardHaptic } from "../../../data/haptics"; import { domainToName } from "../../../data/integration"; import { ActionConfig } from "../../../data/lovelace/config/action"; +import { callExecuteScript } from "../../../data/service"; import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box"; import { showVoiceCommandDialog } from "../../../dialogs/voice-command-dialog/show-ha-voice-command-dialog"; import { HomeAssistant } from "../../../types"; @@ -159,14 +160,11 @@ export const handleAction = async ( forwardHaptic("failure"); return; } - const [domain, service] = (actionConfig.perform_action || - actionConfig.service)!.split(".", 2); - hass.callService( - domain, - service, - actionConfig.data ?? actionConfig.service_data, - actionConfig.target - ); + callExecuteScript(hass, { + action: actionConfig.perform_action || actionConfig.service, + target: actionConfig.target, + data: actionConfig.data ?? actionConfig.service_data, + }); forwardHaptic("light"); break; }