mirror of
https://github.com/home-assistant/frontend.git
synced 2025-11-09 19:09:48 +00:00
Change UI of script entities (#6371)
This commit is contained in:
@@ -7,9 +7,15 @@ import { navigate } from "../common/navigate";
|
||||
import { HomeAssistant } from "../types";
|
||||
import { Condition } from "./automation";
|
||||
|
||||
export const MODES = ["single", "restart", "queued", "parallel"];
|
||||
export const MODES_MAX = ["queued", "parallel"];
|
||||
|
||||
export interface ScriptEntity extends HassEntityBase {
|
||||
attributes: HassEntityAttributeBase & {
|
||||
last_triggered: string;
|
||||
mode: "single" | "restart" | "queued" | "parallel";
|
||||
current?: number;
|
||||
max?: number;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -66,6 +72,20 @@ export const triggerScript = (
|
||||
variables?: {}
|
||||
) => hass.callService("script", computeObjectId(entityId), variables);
|
||||
|
||||
export const canExcecute = (state: ScriptEntity) => {
|
||||
if (state.state === "off") {
|
||||
return true;
|
||||
}
|
||||
if (
|
||||
state.state === "on" &&
|
||||
MODES_MAX.includes(state.attributes.mode) &&
|
||||
state.attributes.current! < state.attributes.max!
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
export const deleteScript = (hass: HomeAssistant, objectId: string) =>
|
||||
hass.callApi("DELETE", `config/script/config/${objectId}`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user