mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Run script in script editor open more info if fields (#19982)
* Run script in script editor open more info if fields * Extract function
This commit is contained in:
parent
7f44e89829
commit
9de59131f4
@ -26,6 +26,7 @@ import {
|
|||||||
Trigger,
|
Trigger,
|
||||||
} from "./automation";
|
} from "./automation";
|
||||||
import { BlueprintInput } from "./blueprint";
|
import { BlueprintInput } from "./blueprint";
|
||||||
|
import { computeObjectId } from "../common/entity/compute_object_id";
|
||||||
|
|
||||||
export const MODES = ["single", "restart", "queued", "parallel"] as const;
|
export const MODES = ["single", "restart", "queued", "parallel"] as const;
|
||||||
export const MODES_MAX = ["queued", "parallel"] as const;
|
export const MODES_MAX = ["queued", "parallel"] as const;
|
||||||
@ -404,3 +405,11 @@ export const getActionType = (action: Action): ActionType => {
|
|||||||
}
|
}
|
||||||
return "unknown";
|
return "unknown";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const hasScriptFields = (
|
||||||
|
hass: HomeAssistant,
|
||||||
|
entityId: string
|
||||||
|
): boolean => {
|
||||||
|
const fields = hass.services.script[computeObjectId(entityId)]?.fields;
|
||||||
|
return fields !== undefined && Object.keys(fields).length > 0;
|
||||||
|
};
|
||||||
|
@ -48,6 +48,7 @@ import {
|
|||||||
fetchScriptFileConfig,
|
fetchScriptFileConfig,
|
||||||
getScriptEditorInitData,
|
getScriptEditorInitData,
|
||||||
getScriptStateConfig,
|
getScriptStateConfig,
|
||||||
|
hasScriptFields,
|
||||||
isMaxMode,
|
isMaxMode,
|
||||||
showScriptEditor,
|
showScriptEditor,
|
||||||
triggerScript,
|
triggerScript,
|
||||||
@ -62,6 +63,7 @@ import { showToast } from "../../../util/toast";
|
|||||||
import "./blueprint-script-editor";
|
import "./blueprint-script-editor";
|
||||||
import "./manual-script-editor";
|
import "./manual-script-editor";
|
||||||
import type { HaManualScriptEditor } from "./manual-script-editor";
|
import type { HaManualScriptEditor } from "./manual-script-editor";
|
||||||
|
import { showMoreInfoDialog } from "../../../dialogs/more-info/show-ha-more-info-dialog";
|
||||||
|
|
||||||
export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
|
export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
@ -611,6 +613,14 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
|
|
||||||
private async _runScript(ev: CustomEvent) {
|
private async _runScript(ev: CustomEvent) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
|
|
||||||
|
if (hasScriptFields(this.hass, this._entityId!)) {
|
||||||
|
showMoreInfoDialog(this, {
|
||||||
|
entityId: this._entityId!,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await triggerScript(this.hass, this.scriptId!);
|
await triggerScript(this.hass, this.scriptId!);
|
||||||
showToast(this, {
|
showToast(this, {
|
||||||
message: this.hass.localize("ui.notification_toast.triggered", {
|
message: this.hass.localize("ui.notification_toast.triggered", {
|
||||||
|
@ -9,13 +9,12 @@ import {
|
|||||||
} from "lit";
|
} from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { isUnavailableState } from "../../../data/entity";
|
import { isUnavailableState } from "../../../data/entity";
|
||||||
import { canRun, ScriptEntity } from "../../../data/script";
|
import { canRun, hasScriptFields, ScriptEntity } from "../../../data/script";
|
||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
import { hasConfigOrEntityChanged } from "../common/has-changed";
|
import { hasConfigOrEntityChanged } from "../common/has-changed";
|
||||||
import "../components/hui-generic-entity-row";
|
import "../components/hui-generic-entity-row";
|
||||||
import { createEntityNotFoundWarning } from "../components/hui-warning";
|
import { createEntityNotFoundWarning } from "../components/hui-warning";
|
||||||
import { ActionRowConfig, LovelaceRow } from "./types";
|
import { ActionRowConfig, LovelaceRow } from "./types";
|
||||||
import { computeObjectId } from "../../../common/entity/compute_object_id";
|
|
||||||
import { showMoreInfoDialog } from "../../../dialogs/more-info/show-ha-more-info-dialog";
|
import { showMoreInfoDialog } from "../../../dialogs/more-info/show-ha-more-info-dialog";
|
||||||
|
|
||||||
@customElement("hui-script-entity-row")
|
@customElement("hui-script-entity-row")
|
||||||
@ -95,10 +94,7 @@ class HuiScriptEntityRow extends LitElement implements LovelaceRow {
|
|||||||
private _runScript(ev): void {
|
private _runScript(ev): void {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
|
|
||||||
const fields =
|
if (hasScriptFields(this.hass!, this._config!.entity)) {
|
||||||
this.hass!.services.script[computeObjectId(this._config!.entity)]?.fields;
|
|
||||||
|
|
||||||
if (fields && Object.keys(fields).length > 0) {
|
|
||||||
showMoreInfoDialog(this, { entityId: this._config!.entity });
|
showMoreInfoDialog(this, { entityId: this._config!.entity });
|
||||||
} else {
|
} else {
|
||||||
this._callService("turn_on");
|
this._callService("turn_on");
|
||||||
|
@ -5,10 +5,9 @@ import { customElement, property } from "lit/decorators";
|
|||||||
import "../components/entity/ha-entity-toggle";
|
import "../components/entity/ha-entity-toggle";
|
||||||
import "../components/entity/state-info";
|
import "../components/entity/state-info";
|
||||||
import { isUnavailableState } from "../data/entity";
|
import { isUnavailableState } from "../data/entity";
|
||||||
import { canRun, ScriptEntity } from "../data/script";
|
import { canRun, hasScriptFields, ScriptEntity } from "../data/script";
|
||||||
import { haStyle } from "../resources/styles";
|
import { haStyle } from "../resources/styles";
|
||||||
import { HomeAssistant } from "../types";
|
import { HomeAssistant } from "../types";
|
||||||
import { computeObjectId } from "../common/entity/compute_object_id";
|
|
||||||
import { showMoreInfoDialog } from "../dialogs/more-info/show-ha-more-info-dialog";
|
import { showMoreInfoDialog } from "../dialogs/more-info/show-ha-more-info-dialog";
|
||||||
|
|
||||||
@customElement("state-card-script")
|
@customElement("state-card-script")
|
||||||
@ -59,11 +58,7 @@ class StateCardScript extends LitElement {
|
|||||||
private _runScript(ev: Event) {
|
private _runScript(ev: Event) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
|
|
||||||
const fields =
|
if (hasScriptFields(this.hass, this.stateObj.entity_id)) {
|
||||||
this.hass!.services.script[computeObjectId(this.stateObj.entity_id)]
|
|
||||||
?.fields;
|
|
||||||
|
|
||||||
if (fields && Object.keys(fields).length > 0) {
|
|
||||||
showMoreInfoDialog(this, { entityId: this.stateObj.entity_id });
|
showMoreInfoDialog(this, { entityId: this.stateObj.entity_id });
|
||||||
} else {
|
} else {
|
||||||
this._callService("turn_on");
|
this._callService("turn_on");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user