From 0fa9c7e456a7d7cfcedf7ab48454872fa08647dd Mon Sep 17 00:00:00 2001
From: Simon Lamon <32477463+silamon@users.noreply.github.com>
Date: Sat, 20 Jul 2024 07:50:33 +0000
Subject: [PATCH] service_data into data and target
---
.../buttons/ha-call-service-button.ts | 18 ++++++++++++++----
.../zha/zha-cluster-attributes.ts | 2 +-
.../zha/zha-cluster-commands.ts | 2 +-
.../integration-panels/zha/zha-device-card.ts | 1 -
.../elements/hui-service-button-element.ts | 7 ++++++-
src/panels/lovelace/elements/types.ts | 4 ++++
6 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/src/components/buttons/ha-call-service-button.ts b/src/components/buttons/ha-call-service-button.ts
index 3cea93de0d94..3fc835e14a38 100644
--- a/src/components/buttons/ha-call-service-button.ts
+++ b/src/components/buttons/ha-call-service-button.ts
@@ -1,5 +1,6 @@
import { LitElement, TemplateResult, html } from "lit";
import { customElement, property } from "lit/decorators";
+import { HassServiceTarget } from "home-assistant-js-websocket";
import { showConfirmationDialog } from "../../dialogs/generic/show-dialog-box";
import "./ha-progress-button";
import { HomeAssistant } from "../../types";
@@ -17,7 +18,9 @@ class HaCallServiceButton extends LitElement {
@property() public service!: string;
- @property({ type: Object }) public serviceData = {};
+ @property({ type: Object }) public target!: HassServiceTarget;
+
+ @property({ type: Object }) public data = {};
@property() public confirmation?;
@@ -39,7 +42,8 @@ class HaCallServiceButton extends LitElement {
const eventData = {
domain: this.domain,
service: this.service,
- serviceData: this.serviceData,
+ data: this.data,
+ target: this.target,
success: false,
};
@@ -47,7 +51,12 @@ class HaCallServiceButton extends LitElement {
this.shadowRoot!.querySelector("ha-progress-button")!;
try {
- await this.hass.callService(this.domain, this.service, this.serviceData);
+ await this.hass.callService(
+ this.domain,
+ this.service,
+ this.data,
+ this.target
+ );
this.progress = false;
progressElement.actionSuccess();
eventData.success = true;
@@ -85,7 +94,8 @@ declare global {
"hass-service-called": {
domain: string;
service: string;
- serviceData: object;
+ target: HassServiceTarget;
+ data: object;
success: boolean;
};
}
diff --git a/src/panels/config/integrations/integration-panels/zha/zha-cluster-attributes.ts b/src/panels/config/integrations/integration-panels/zha/zha-cluster-attributes.ts
index e3462fd69ec2..9b628d469961 100644
--- a/src/panels/config/integrations/integration-panels/zha/zha-cluster-attributes.ts
+++ b/src/panels/config/integrations/integration-panels/zha/zha-cluster-attributes.ts
@@ -134,7 +134,7 @@ export class ZHAClusterAttributes extends LitElement {
.hass=${this.hass}
domain="zha"
service="set_zigbee_cluster_attribute"
- .serviceData=${this._setAttributeServiceData}
+ .data=${this._setAttributeServiceData}
>
${this.hass!.localize(
"ui.panel.config.zha.cluster_attributes.write_zigbee_attribute"
diff --git a/src/panels/config/integrations/integration-panels/zha/zha-cluster-commands.ts b/src/panels/config/integrations/integration-panels/zha/zha-cluster-commands.ts
index d6932b10ff30..4ea3417261b6 100644
--- a/src/panels/config/integrations/integration-panels/zha/zha-cluster-commands.ts
+++ b/src/panels/config/integrations/integration-panels/zha/zha-cluster-commands.ts
@@ -115,7 +115,7 @@ export class ZHAClusterCommands extends LitElement {
.hass=${this.hass}
domain="zha"
service="issue_zigbee_cluster_command"
- .serviceData=${this._issueClusterCommandServiceData}
+ .data=${this._issueClusterCommandServiceData}
.disabled=${!this._canIssueCommand}
>
${this.hass!.localize(
diff --git a/src/panels/config/integrations/integration-panels/zha/zha-device-card.ts b/src/panels/config/integrations/integration-panels/zha/zha-device-card.ts
index 695a9bd9dca9..78a0ae9ef448 100644
--- a/src/panels/config/integrations/integration-panels/zha/zha-device-card.ts
+++ b/src/panels/config/integrations/integration-panels/zha/zha-device-card.ts
@@ -6,7 +6,6 @@ import { fireEvent } from "../../../../../common/dom/fire_event";
import { computeStateName } from "../../../../../common/entity/compute_state_name";
import { stringCompare } from "../../../../../common/string/compare";
import { slugify } from "../../../../../common/string/slugify";
-import "../../../../../components/buttons/ha-call-service-button";
import "../../../../../components/entity/state-badge";
import "../../../../../components/ha-area-picker";
import "../../../../../components/ha-card";
diff --git a/src/panels/lovelace/elements/hui-service-button-element.ts b/src/panels/lovelace/elements/hui-service-button-element.ts
index 91c8abcb75f6..4860ed19d739 100644
--- a/src/panels/lovelace/elements/hui-service-button-element.ts
+++ b/src/panels/lovelace/elements/hui-service-button-element.ts
@@ -40,12 +40,17 @@ export class HuiServiceButtonElement
return nothing;
}
+ const updatedTarget = this._config.target ?? {
+ entity_id: this._config.service_data?.entity_id,
+ };
+
return html`
${this._config.title}
`;
diff --git a/src/panels/lovelace/elements/types.ts b/src/panels/lovelace/elements/types.ts
index 2cddae5721d6..35b2c453a8a6 100644
--- a/src/panels/lovelace/elements/types.ts
+++ b/src/panels/lovelace/elements/types.ts
@@ -1,3 +1,4 @@
+import { HassServiceTarget } from "home-assistant-js-websocket";
import { ActionConfig } from "../../../data/lovelace/config/action";
import { HomeAssistant } from "../../../types";
import { Condition } from "../common/validate-condition";
@@ -56,7 +57,10 @@ export interface ImageElementConfig extends LovelaceElementConfigBase {
export interface ServiceButtonElementConfig extends LovelaceElementConfigBase {
title?: string;
service?: string;
+ target?: HassServiceTarget;
+ // "service_data" is kept for backwards compatibility. Replaced by "data".
service_data?: Record;
+ data?: Record;
}
export interface StateBadgeElementConfig extends LovelaceElementConfigBase {