Change UI of script entities (#6371)

This commit is contained in:
Bram Kragten
2020-07-14 19:48:11 +02:00
committed by GitHub
parent 98656b0044
commit e70a3e09bf
6 changed files with 138 additions and 102 deletions

View File

@@ -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}`);