mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-22 16:56:35 +00:00
Add stop script/automation action (#12299)
This commit is contained in:
parent
22175a7271
commit
aa562c21a8
@ -206,6 +206,12 @@ export interface VariablesAction {
|
||||
variables: Record<string, unknown>;
|
||||
}
|
||||
|
||||
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)) {
|
||||
|
@ -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) => {
|
||||
|
@ -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`
|
||||
<ha-textfield
|
||||
.label=${this.hass.localize(
|
||||
"ui.panel.config.automation.editor.actions.type.stop.stop"
|
||||
)}
|
||||
.value=${stop}
|
||||
@change=${this._stopChanged}
|
||||
></ha-textfield>
|
||||
<ha-formfield
|
||||
.label=${this.hass.localize(
|
||||
"ui.panel.config.automation.editor.actions.type.stop.error"
|
||||
)}
|
||||
>
|
||||
<ha-switch
|
||||
.checked=${error ?? false}
|
||||
@change=${this._errorChanged}
|
||||
></ha-switch>
|
||||
</ha-formfield>
|
||||
`;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -2020,6 +2020,11 @@
|
||||
"if": "If",
|
||||
"then": "Then",
|
||||
"else": "Else"
|
||||
},
|
||||
"stop": {
|
||||
"label": "Stop",
|
||||
"stop": "Reason for stopping",
|
||||
"error": "Stop because of an unexpected error"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user