diff --git a/src/data/script.ts b/src/data/script.ts index 4262fcd1e4..3966651a4a 100644 --- a/src/data/script.ts +++ b/src/data/script.ts @@ -206,6 +206,12 @@ export interface VariablesAction { variables: Record; } +export interface StopAction { + alias?: string; + stop: string; + error?: boolean; +} + interface UnknownAction { alias?: string; [key: string]: unknown; @@ -225,6 +231,7 @@ export type Action = | IfAction | VariablesAction | PlayMediaAction + | StopAction | UnknownAction; export interface ActionTypes { @@ -241,6 +248,7 @@ export interface ActionTypes { variables: VariablesAction; service: ServiceAction; play_media: PlayMediaAction; + stop: StopAction; unknown: UnknownAction; } @@ -317,6 +325,9 @@ export const getActionType = (action: Action): ActionType => { if ("variables" in action) { return "variables"; } + if ("stop" in action) { + return "stop"; + } if ("service" in action) { if ("metadata" in action) { if (is(action, activateSceneActionStruct)) { diff --git a/src/panels/config/automation/action/ha-automation-action-row.ts b/src/panels/config/automation/action/ha-automation-action-row.ts index c049ca493c..40e9b4764f 100644 --- a/src/panels/config/automation/action/ha-automation-action-row.ts +++ b/src/panels/config/automation/action/ha-automation-action-row.ts @@ -36,6 +36,7 @@ import "./types/ha-automation-action-if"; import "./types/ha-automation-action-play_media"; import "./types/ha-automation-action-repeat"; import "./types/ha-automation-action-service"; +import "./types/ha-automation-action-stop"; import "./types/ha-automation-action-wait_for_trigger"; import "./types/ha-automation-action-wait_template"; @@ -52,6 +53,7 @@ const OPTIONS = [ "choose", "if", "device_id", + "stop", ]; const getType = (action: Action | undefined) => { diff --git a/src/panels/config/automation/action/types/ha-automation-action-stop.ts b/src/panels/config/automation/action/types/ha-automation-action-stop.ts new file mode 100644 index 0000000000..711784f767 --- /dev/null +++ b/src/panels/config/automation/action/types/ha-automation-action-stop.ts @@ -0,0 +1,71 @@ +import { css, CSSResultGroup, html, LitElement } from "lit"; +import { customElement, property } from "lit/decorators"; +import { fireEvent } from "../../../../../common/dom/fire_event"; +import "../../../../../components/ha-textfield"; +import { StopAction } from "../../../../../data/script"; +import { HomeAssistant } from "../../../../../types"; +import { ActionElement } from "../ha-automation-action-row"; + +@customElement("ha-automation-action-stop") +export class HaStopAction extends LitElement implements ActionElement { + @property({ attribute: false }) public hass!: HomeAssistant; + + @property() public action!: StopAction; + + public static get defaultConfig() { + return { stop: "" }; + } + + protected render() { + const { error, stop } = this.action; + + return html` + + + + + `; + } + + private _stopChanged(ev: CustomEvent) { + ev.stopPropagation(); + fireEvent(this, "value-changed", { + value: { ...this.action, stop: (ev.target as any).value }, + }); + } + + private _errorChanged(ev: CustomEvent) { + ev.stopPropagation(); + fireEvent(this, "value-changed", { + value: { ...this.action, error: (ev.target as any).checked }, + }); + } + + static get styles(): CSSResultGroup { + return css` + ha-textfield { + display: block; + margin-bottom: 24px; + } + `; + } +} + +declare global { + interface HTMLElementTagNameMap { + "ha-automation-action-stop": HaStopAction; + } +} diff --git a/src/translations/en.json b/src/translations/en.json index 4aa28eb0a4..f165746cfb 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -2020,6 +2020,11 @@ "if": "If", "then": "Then", "else": "Else" + }, + "stop": { + "label": "Stop", + "stop": "Reason for stopping", + "error": "Stop because of an unexpected error" } } }