mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-05 08:26:35 +00:00
Add parallel automation/script action (#12491)
This commit is contained in:
parent
38b4090daa
commit
8c97aee1fe
@ -62,6 +62,17 @@ const ACTIONS = [
|
|||||||
entity_id: "input_boolean.toggle_4",
|
entity_id: "input_boolean.toggle_4",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
parallel: [
|
||||||
|
{ scene: "scene.kitchen_morning" },
|
||||||
|
{
|
||||||
|
service: "media_player.play_media",
|
||||||
|
target: { entity_id: "media_player.living_room" },
|
||||||
|
data: { media_content_id: "", media_content_type: "" },
|
||||||
|
metadata: { title: "Happy Song" },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@customElement("demo-automation-describe-action")
|
@customElement("demo-automation-describe-action")
|
||||||
|
@ -20,6 +20,7 @@ import { HaWaitForTriggerAction } from "../../../../src/panels/config/automation
|
|||||||
import { HaWaitAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-wait_template";
|
import { HaWaitAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-wait_template";
|
||||||
import { Action } from "../../../../src/data/script";
|
import { Action } from "../../../../src/data/script";
|
||||||
import { HaConditionAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-condition";
|
import { HaConditionAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-condition";
|
||||||
|
import { HaParallelAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-parallel";
|
||||||
|
|
||||||
const SCHEMAS: { name: string; actions: Action[] }[] = [
|
const SCHEMAS: { name: string; actions: Action[] }[] = [
|
||||||
{ name: "Event", actions: [HaEventAction.defaultConfig] },
|
{ name: "Event", actions: [HaEventAction.defaultConfig] },
|
||||||
@ -33,6 +34,7 @@ const SCHEMAS: { name: string; actions: Action[] }[] = [
|
|||||||
{ name: "Repeat", actions: [HaRepeatAction.defaultConfig] },
|
{ name: "Repeat", actions: [HaRepeatAction.defaultConfig] },
|
||||||
{ name: "Choose", actions: [HaChooseAction.defaultConfig] },
|
{ name: "Choose", actions: [HaChooseAction.defaultConfig] },
|
||||||
{ name: "Variables", actions: [{ variables: { hello: "1" } }] },
|
{ name: "Variables", actions: [{ variables: { hello: "1" } }] },
|
||||||
|
{ name: "Parallel", actions: [HaParallelAction.defaultConfig] },
|
||||||
];
|
];
|
||||||
|
|
||||||
@customElement("demo-automation-editor-action")
|
@customElement("demo-automation-editor-action")
|
||||||
|
@ -203,6 +203,10 @@ export interface StopAction extends BaseAction {
|
|||||||
error?: boolean;
|
error?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ParallelAction extends BaseAction {
|
||||||
|
parallel: Action | Action[];
|
||||||
|
}
|
||||||
|
|
||||||
interface UnknownAction extends BaseAction {
|
interface UnknownAction extends BaseAction {
|
||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
}
|
}
|
||||||
@ -222,6 +226,7 @@ export type Action =
|
|||||||
| VariablesAction
|
| VariablesAction
|
||||||
| PlayMediaAction
|
| PlayMediaAction
|
||||||
| StopAction
|
| StopAction
|
||||||
|
| ParallelAction
|
||||||
| UnknownAction;
|
| UnknownAction;
|
||||||
|
|
||||||
export interface ActionTypes {
|
export interface ActionTypes {
|
||||||
@ -239,6 +244,7 @@ export interface ActionTypes {
|
|||||||
service: ServiceAction;
|
service: ServiceAction;
|
||||||
play_media: PlayMediaAction;
|
play_media: PlayMediaAction;
|
||||||
stop: StopAction;
|
stop: StopAction;
|
||||||
|
parallel: ParallelAction;
|
||||||
unknown: UnknownAction;
|
unknown: UnknownAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -318,6 +324,9 @@ export const getActionType = (action: Action): ActionType => {
|
|||||||
if ("stop" in action) {
|
if ("stop" in action) {
|
||||||
return "stop";
|
return "stop";
|
||||||
}
|
}
|
||||||
|
if ("parallel" in action) {
|
||||||
|
return "parallel";
|
||||||
|
}
|
||||||
if ("service" in action) {
|
if ("service" in action) {
|
||||||
if ("metadata" in action) {
|
if ("metadata" in action) {
|
||||||
if (is(action, activateSceneActionStruct)) {
|
if (is(action, activateSceneActionStruct)) {
|
||||||
|
@ -169,5 +169,9 @@ export const describeAction = <T extends ActionType>(
|
|||||||
}`;
|
}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (actionType === "parallel") {
|
||||||
|
return "Run in parallel";
|
||||||
|
}
|
||||||
|
|
||||||
return actionType;
|
return actionType;
|
||||||
};
|
};
|
||||||
|
@ -33,6 +33,7 @@ import "./types/ha-automation-action-delay";
|
|||||||
import "./types/ha-automation-action-device_id";
|
import "./types/ha-automation-action-device_id";
|
||||||
import "./types/ha-automation-action-event";
|
import "./types/ha-automation-action-event";
|
||||||
import "./types/ha-automation-action-if";
|
import "./types/ha-automation-action-if";
|
||||||
|
import "./types/ha-automation-action-parallel";
|
||||||
import "./types/ha-automation-action-play_media";
|
import "./types/ha-automation-action-play_media";
|
||||||
import "./types/ha-automation-action-repeat";
|
import "./types/ha-automation-action-repeat";
|
||||||
import "./types/ha-automation-action-service";
|
import "./types/ha-automation-action-service";
|
||||||
@ -54,6 +55,7 @@ const OPTIONS = [
|
|||||||
"if",
|
"if",
|
||||||
"device_id",
|
"device_id",
|
||||||
"stop",
|
"stop",
|
||||||
|
"parallel",
|
||||||
];
|
];
|
||||||
|
|
||||||
const getType = (action: Action | undefined) => {
|
const getType = (action: Action | undefined) => {
|
||||||
|
@ -0,0 +1,56 @@
|
|||||||
|
import { CSSResultGroup, html, LitElement } from "lit";
|
||||||
|
import { customElement, property } from "lit/decorators";
|
||||||
|
import { fireEvent } from "../../../../../common/dom/fire_event";
|
||||||
|
import { Action, ParallelAction } from "../../../../../data/script";
|
||||||
|
import { HaDeviceAction } from "./ha-automation-action-device_id";
|
||||||
|
import { haStyle } from "../../../../../resources/styles";
|
||||||
|
import type { HomeAssistant } from "../../../../../types";
|
||||||
|
import "../ha-automation-action";
|
||||||
|
import "../../../../../components/ha-textfield";
|
||||||
|
import type { ActionElement } from "../ha-automation-action-row";
|
||||||
|
|
||||||
|
@customElement("ha-automation-action-parallel")
|
||||||
|
export class HaParallelAction extends LitElement implements ActionElement {
|
||||||
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
|
@property({ attribute: false }) public action!: ParallelAction;
|
||||||
|
|
||||||
|
public static get defaultConfig() {
|
||||||
|
return {
|
||||||
|
parallel: [HaDeviceAction.defaultConfig],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected render() {
|
||||||
|
const action = this.action;
|
||||||
|
|
||||||
|
return html`
|
||||||
|
<ha-automation-action
|
||||||
|
.actions=${action.parallel}
|
||||||
|
@value-changed=${this._actionsChanged}
|
||||||
|
.hass=${this.hass}
|
||||||
|
></ha-automation-action>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _actionsChanged(ev: CustomEvent) {
|
||||||
|
ev.stopPropagation();
|
||||||
|
const value = ev.detail.value as Action[];
|
||||||
|
fireEvent(this, "value-changed", {
|
||||||
|
value: {
|
||||||
|
...this.action,
|
||||||
|
parallel: value,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static get styles(): CSSResultGroup {
|
||||||
|
return haStyle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"ha-automation-action-parallel": HaParallelAction;
|
||||||
|
}
|
||||||
|
}
|
@ -2053,6 +2053,9 @@
|
|||||||
"label": "Stop",
|
"label": "Stop",
|
||||||
"stop": "Reason for stopping",
|
"stop": "Reason for stopping",
|
||||||
"error": "Stop because of an unexpected error"
|
"error": "Stop because of an unexpected error"
|
||||||
|
},
|
||||||
|
"parallel": {
|
||||||
|
"label": "Run in parallel"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user