@@ -36,17 +98,63 @@ class MoreInfoScript extends LitElement {
`;
}
+ protected override willUpdate(changedProperties: PropertyValues): void {
+ super.willUpdate(changedProperties);
+
+ if (!changedProperties.has("stateObj")) {
+ return;
+ }
+
+ const oldState = changedProperties.get("stateObj") as
+ | HassEntity
+ | undefined;
+ const newState = this.stateObj;
+
+ if (newState && (!oldState || oldState.entity_id !== newState.entity_id)) {
+ this._scriptData = { service: newState.entity_id, data: {} };
+ }
+ }
+
+ private _cancelScript(ev: Event) {
+ ev.stopPropagation();
+ this._callService("turn_off");
+ }
+
+ private async _runScript(ev: Event) {
+ ev.stopPropagation();
+ this.hass.callService(
+ "script",
+ computeObjectId(this.stateObj!.entity_id),
+ this._scriptData
+ );
+ }
+
+ private _callService(service: string): void {
+ this.hass.callService("script", service, {
+ entity_id: this.stateObj!.entity_id,
+ });
+ }
+
+ private _scriptDataChanged(ev: CustomEvent): void {
+ this._scriptData = { ...this._scriptData, ...ev.detail.value };
+ }
+
static get styles(): CSSResultGroup {
return css`
.flex {
display: flex;
justify-content: space-between;
+ margin-bottom: 16px;
}
hr {
border-color: var(--divider-color);
border-bottom: none;
margin: 16px 0;
}
+ ha-service-control {
+ --service-control-padding: 0;
+ --service-control-items-border-top: none;
+ }
`;
}
}
diff --git a/src/panels/lovelace/entity-rows/hui-script-entity-row.ts b/src/panels/lovelace/entity-rows/hui-script-entity-row.ts
index 6fa20512ea..1147d405b4 100644
--- a/src/panels/lovelace/entity-rows/hui-script-entity-row.ts
+++ b/src/panels/lovelace/entity-rows/hui-script-entity-row.ts
@@ -15,6 +15,8 @@ import { hasConfigOrEntityChanged } from "../common/has-changed";
import "../components/hui-generic-entity-row";
import { createEntityNotFoundWarning } from "../components/hui-warning";
import { ActionRowConfig, LovelaceRow } from "./types";
+import { computeObjectId } from "../../../common/entity/compute_object_id";
+import { showMoreInfoDialog } from "../../../dialogs/more-info/show-ha-more-info-dialog";
@customElement("hui-script-entity-row")
class HuiScriptEntityRow extends LitElement implements LovelaceRow {
@@ -92,7 +94,15 @@ class HuiScriptEntityRow extends LitElement implements LovelaceRow {
private _runScript(ev): void {
ev.stopPropagation();
- this._callService("turn_on");
+
+ const fields =
+ this.hass!.services.script[computeObjectId(this._config!.entity)]?.fields;
+
+ if (fields && Object.keys(fields).length > 0) {
+ showMoreInfoDialog(this, { entityId: this._config!.entity });
+ } else {
+ this._callService("turn_on");
+ }
}
private _callService(service: string): void {
diff --git a/src/state-summary/state-card-script.ts b/src/state-summary/state-card-script.ts
index f8014684e7..fc375d8d25 100644
--- a/src/state-summary/state-card-script.ts
+++ b/src/state-summary/state-card-script.ts
@@ -8,6 +8,8 @@ import { isUnavailableState } from "../data/entity";
import { canRun, ScriptEntity } from "../data/script";
import { haStyle } from "../resources/styles";
import { HomeAssistant } from "../types";
+import { computeObjectId } from "../common/entity/compute_object_id";
+import { showMoreInfoDialog } from "../dialogs/more-info/show-ha-more-info-dialog";
@customElement("state-card-script")
class StateCardScript extends LitElement {
@@ -56,7 +58,16 @@ class StateCardScript extends LitElement {
private _runScript(ev: Event) {
ev.stopPropagation();
- this._callService("turn_on");
+
+ const fields =
+ this.hass!.services.script[computeObjectId(this.stateObj.entity_id)]
+ ?.fields;
+
+ if (fields && Object.keys(fields).length > 0) {
+ showMoreInfoDialog(this, { entityId: this.stateObj.entity_id });
+ } else {
+ this._callService("turn_on");
+ }
}
private _callService(service: string): void {