mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-22 00:36:34 +00:00
Remove activate scene in automation editor (#22258)
This commit is contained in:
parent
f7f936cb54
commit
6a337cc486
@ -15,7 +15,6 @@ import { HaDelayAction } from "../../../../src/panels/config/automation/action/t
|
|||||||
import { HaDeviceAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-device_id";
|
import { HaDeviceAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-device_id";
|
||||||
import { HaEventAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-event";
|
import { HaEventAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-event";
|
||||||
import { HaRepeatAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-repeat";
|
import { HaRepeatAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-repeat";
|
||||||
import { HaSceneAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-activate_scene";
|
|
||||||
import { HaServiceAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-service";
|
import { HaServiceAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-service";
|
||||||
import { HaWaitForTriggerAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-wait_for_trigger";
|
import { HaWaitForTriggerAction } from "../../../../src/panels/config/automation/action/types/ha-automation-action-wait_for_trigger";
|
||||||
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";
|
||||||
@ -33,7 +32,6 @@ const SCHEMAS: { name: string; actions: Action[] }[] = [
|
|||||||
{ name: "Service", actions: [HaServiceAction.defaultConfig] },
|
{ name: "Service", actions: [HaServiceAction.defaultConfig] },
|
||||||
{ name: "Condition", actions: [HaConditionAction.defaultConfig] },
|
{ name: "Condition", actions: [HaConditionAction.defaultConfig] },
|
||||||
{ name: "Delay", actions: [HaDelayAction.defaultConfig] },
|
{ name: "Delay", actions: [HaDelayAction.defaultConfig] },
|
||||||
{ name: "Scene", actions: [HaSceneAction.defaultConfig] },
|
|
||||||
{ name: "Play media", actions: [HaPlayMediaAction.defaultConfig] },
|
{ name: "Play media", actions: [HaPlayMediaAction.defaultConfig] },
|
||||||
{ name: "Wait", actions: [HaWaitAction.defaultConfig] },
|
{ name: "Wait", actions: [HaWaitAction.defaultConfig] },
|
||||||
{ name: "WaitForTrigger", actions: [HaWaitForTriggerAction.defaultConfig] },
|
{ name: "WaitForTrigger", actions: [HaWaitForTriggerAction.defaultConfig] },
|
||||||
|
@ -11,7 +11,6 @@ import {
|
|||||||
mdiFormatListNumbered,
|
mdiFormatListNumbered,
|
||||||
mdiGestureDoubleTap,
|
mdiGestureDoubleTap,
|
||||||
mdiHandBackRight,
|
mdiHandBackRight,
|
||||||
mdiPalette,
|
|
||||||
mdiPlay,
|
mdiPlay,
|
||||||
mdiRefresh,
|
mdiRefresh,
|
||||||
mdiRoomService,
|
mdiRoomService,
|
||||||
@ -27,7 +26,6 @@ export const ACTION_ICONS = {
|
|||||||
delay: mdiTimerOutline,
|
delay: mdiTimerOutline,
|
||||||
event: mdiGestureDoubleTap,
|
event: mdiGestureDoubleTap,
|
||||||
play_media: mdiPlay,
|
play_media: mdiPlay,
|
||||||
activate_scene: mdiPalette,
|
|
||||||
service: mdiRoomService,
|
service: mdiRoomService,
|
||||||
wait_template: mdiCodeBraces,
|
wait_template: mdiCodeBraces,
|
||||||
wait_for_trigger: mdiTrafficLight,
|
wait_for_trigger: mdiTrafficLight,
|
||||||
|
@ -72,16 +72,6 @@ const playMediaActionStruct: Describe<PlayMediaAction> = assign(
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
const activateSceneActionStruct: Describe<ServiceSceneAction> = assign(
|
|
||||||
baseActionStruct,
|
|
||||||
object({
|
|
||||||
action: literal("scene.turn_on"),
|
|
||||||
target: optional(object({ entity_id: optional(string()) })),
|
|
||||||
entity_id: optional(string()),
|
|
||||||
metadata: object(),
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
export interface ScriptEntity extends HassEntityBase {
|
export interface ScriptEntity extends HassEntityBase {
|
||||||
attributes: HassEntityAttributeBase & {
|
attributes: HassEntityAttributeBase & {
|
||||||
last_triggered: string;
|
last_triggered: string;
|
||||||
@ -161,17 +151,6 @@ export interface DelayAction extends BaseAction {
|
|||||||
delay: number | Partial<DelayActionParts> | string;
|
delay: number | Partial<DelayActionParts> | string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ServiceSceneAction extends BaseAction {
|
|
||||||
action: "scene.turn_on";
|
|
||||||
target?: { entity_id?: string };
|
|
||||||
entity_id?: string;
|
|
||||||
metadata: Record<string, unknown>;
|
|
||||||
}
|
|
||||||
export interface LegacySceneAction extends BaseAction {
|
|
||||||
scene: string;
|
|
||||||
}
|
|
||||||
export type SceneAction = ServiceSceneAction | LegacySceneAction;
|
|
||||||
|
|
||||||
export interface WaitAction extends BaseAction {
|
export interface WaitAction extends BaseAction {
|
||||||
wait_template: string;
|
wait_template: string;
|
||||||
timeout?: number;
|
timeout?: number;
|
||||||
@ -272,7 +251,6 @@ export type NonConditionAction =
|
|||||||
| DeviceAction
|
| DeviceAction
|
||||||
| ServiceAction
|
| ServiceAction
|
||||||
| DelayAction
|
| DelayAction
|
||||||
| SceneAction
|
|
||||||
| WaitAction
|
| WaitAction
|
||||||
| WaitForTriggerAction
|
| WaitForTriggerAction
|
||||||
| RepeatAction
|
| RepeatAction
|
||||||
@ -298,7 +276,6 @@ export interface ActionTypes {
|
|||||||
check_condition: Condition;
|
check_condition: Condition;
|
||||||
fire_event: EventAction;
|
fire_event: EventAction;
|
||||||
device_action: DeviceAction;
|
device_action: DeviceAction;
|
||||||
activate_scene: SceneAction;
|
|
||||||
repeat: RepeatAction;
|
repeat: RepeatAction;
|
||||||
choose: ChooseAction;
|
choose: ChooseAction;
|
||||||
if: IfAction;
|
if: IfAction;
|
||||||
@ -381,9 +358,6 @@ export const getActionType = (action: Action): ActionType => {
|
|||||||
if ("device_id" in action) {
|
if ("device_id" in action) {
|
||||||
return "device_action";
|
return "device_action";
|
||||||
}
|
}
|
||||||
if ("scene" in action) {
|
|
||||||
return "activate_scene";
|
|
||||||
}
|
|
||||||
if ("repeat" in action) {
|
if ("repeat" in action) {
|
||||||
return "repeat";
|
return "repeat";
|
||||||
}
|
}
|
||||||
@ -413,9 +387,6 @@ export const getActionType = (action: Action): ActionType => {
|
|||||||
}
|
}
|
||||||
if ("action" in action || "service" in action) {
|
if ("action" in action || "service" in action) {
|
||||||
if ("metadata" in action) {
|
if ("metadata" in action) {
|
||||||
if (is(action, activateSceneActionStruct)) {
|
|
||||||
return "activate_scene";
|
|
||||||
}
|
|
||||||
if (is(action, playMediaActionStruct)) {
|
if (is(action, playMediaActionStruct)) {
|
||||||
return "play_media";
|
return "play_media";
|
||||||
}
|
}
|
||||||
@ -447,6 +418,15 @@ export const migrateAutomationAction = (
|
|||||||
delete action.service;
|
delete action.service;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// legacy scene (scene: scene_name)
|
||||||
|
if ("scene" in action) {
|
||||||
|
action.action = "scene.turn_on";
|
||||||
|
action.target = {
|
||||||
|
entity_id: action.scene,
|
||||||
|
};
|
||||||
|
delete action.scene;
|
||||||
|
}
|
||||||
|
|
||||||
if ("sequence" in action) {
|
if ("sequence" in action) {
|
||||||
for (const sequenceAction of (action as SequenceAction).sequence) {
|
for (const sequenceAction of (action as SequenceAction).sequence) {
|
||||||
migrateAutomationAction(sequenceAction);
|
migrateAutomationAction(sequenceAction);
|
||||||
|
@ -28,7 +28,6 @@ import type {
|
|||||||
ParallelAction,
|
ParallelAction,
|
||||||
PlayMediaAction,
|
PlayMediaAction,
|
||||||
RepeatAction,
|
RepeatAction,
|
||||||
SceneAction,
|
|
||||||
SequenceAction,
|
SequenceAction,
|
||||||
SetConversationResponseAction,
|
SetConversationResponseAction,
|
||||||
StopAction,
|
StopAction,
|
||||||
@ -297,26 +296,6 @@ const tryDescribeAction = <T extends ActionType>(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actionType === "activate_scene") {
|
|
||||||
const config = action as SceneAction;
|
|
||||||
let entityId: string | undefined;
|
|
||||||
if ("scene" in config) {
|
|
||||||
entityId = config.scene;
|
|
||||||
} else {
|
|
||||||
entityId = config.target?.entity_id || config.entity_id;
|
|
||||||
}
|
|
||||||
if (!entityId) {
|
|
||||||
return hass.localize(
|
|
||||||
`${actionTranslationBaseKey}.activate_scene.description.activate_scene`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const sceneStateObj = entityId ? hass.states[entityId] : undefined;
|
|
||||||
return hass.localize(
|
|
||||||
`${actionTranslationBaseKey}.activate_scene.description.activate_scene_with_name`,
|
|
||||||
{ name: sceneStateObj ? computeStateName(sceneStateObj) : entityId }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (actionType === "play_media") {
|
if (actionType === "play_media") {
|
||||||
const config = action as PlayMediaAction;
|
const config = action as PlayMediaAction;
|
||||||
const entityId = config.target?.entity_id || config.entity_id;
|
const entityId = config.target?.entity_id || config.entity_id;
|
||||||
|
@ -60,7 +60,6 @@ import {
|
|||||||
import { haStyle } from "../../../../resources/styles";
|
import { haStyle } from "../../../../resources/styles";
|
||||||
import type { HomeAssistant } from "../../../../types";
|
import type { HomeAssistant } from "../../../../types";
|
||||||
import { showToast } from "../../../../util/toast";
|
import { showToast } from "../../../../util/toast";
|
||||||
import "./types/ha-automation-action-activate_scene";
|
|
||||||
import "./types/ha-automation-action-choose";
|
import "./types/ha-automation-action-choose";
|
||||||
import "./types/ha-automation-action-condition";
|
import "./types/ha-automation-action-condition";
|
||||||
import "./types/ha-automation-action-delay";
|
import "./types/ha-automation-action-delay";
|
||||||
@ -81,8 +80,8 @@ export const getType = (action: Action | undefined) => {
|
|||||||
if (!action) {
|
if (!action) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
if ("action" in action || "scene" in action) {
|
if ("action" in action) {
|
||||||
return getActionType(action) as "activate_scene" | "action" | "play_media";
|
return getActionType(action) as "action" | "play_media";
|
||||||
}
|
}
|
||||||
if (["and", "or", "not"].some((key) => key in action)) {
|
if (["and", "or", "not"].some((key) => key in action)) {
|
||||||
return "condition" as const;
|
return "condition" as const;
|
||||||
|
@ -1,72 +0,0 @@
|
|||||||
import { html, LitElement } from "lit";
|
|
||||||
import { customElement, property } from "lit/decorators";
|
|
||||||
import { fireEvent } from "../../../../../common/dom/fire_event";
|
|
||||||
import "../../../../../components/entity/ha-entity-picker";
|
|
||||||
import type { SceneAction } from "../../../../../data/script";
|
|
||||||
import type { ValueChangedEvent, HomeAssistant } from "../../../../../types";
|
|
||||||
import type { ActionElement } from "../ha-automation-action-row";
|
|
||||||
|
|
||||||
const includeDomains = ["scene"];
|
|
||||||
|
|
||||||
@customElement("ha-automation-action-activate_scene")
|
|
||||||
export class HaSceneAction extends LitElement implements ActionElement {
|
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
|
||||||
|
|
||||||
@property({ type: Boolean }) public disabled = false;
|
|
||||||
|
|
||||||
@property({ attribute: false }) public action!: SceneAction;
|
|
||||||
|
|
||||||
public static get defaultConfig(): SceneAction {
|
|
||||||
return {
|
|
||||||
action: "scene.turn_on",
|
|
||||||
target: {
|
|
||||||
entity_id: "",
|
|
||||||
},
|
|
||||||
metadata: {},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
protected render() {
|
|
||||||
let scene;
|
|
||||||
|
|
||||||
if ("scene" in this.action) {
|
|
||||||
scene = this.action.scene;
|
|
||||||
} else {
|
|
||||||
scene = this.action.target?.entity_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
return html`
|
|
||||||
<ha-entity-picker
|
|
||||||
.hass=${this.hass}
|
|
||||||
.label=${this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.actions.type.activate_scene.scene"
|
|
||||||
)}
|
|
||||||
.value=${scene}
|
|
||||||
.disabled=${this.disabled}
|
|
||||||
@value-changed=${this._entityPicked}
|
|
||||||
.includeDomains=${includeDomains}
|
|
||||||
allow-custom-entity
|
|
||||||
></ha-entity-picker>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
private _entityPicked(ev: ValueChangedEvent<string>) {
|
|
||||||
ev.stopPropagation();
|
|
||||||
fireEvent(this, "value-changed", {
|
|
||||||
value: {
|
|
||||||
...this.action,
|
|
||||||
action: "scene.turn_on",
|
|
||||||
target: {
|
|
||||||
entity_id: ev.detail.value,
|
|
||||||
},
|
|
||||||
metadata: {},
|
|
||||||
} as SceneAction,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
declare global {
|
|
||||||
interface HTMLElementTagNameMap {
|
|
||||||
"ha-automation-action-activate_scene": HaSceneAction;
|
|
||||||
}
|
|
||||||
}
|
|
@ -3495,14 +3495,6 @@
|
|||||||
"no_device": "Device action"
|
"no_device": "Device action"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"activate_scene": {
|
|
||||||
"label": "Scene",
|
|
||||||
"scene": "Scene",
|
|
||||||
"description": {
|
|
||||||
"activate_scene": "Activate a scene",
|
|
||||||
"activate_scene_with_name": "Activate scene {name}"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"repeat": {
|
"repeat": {
|
||||||
"label": "Repeat",
|
"label": "Repeat",
|
||||||
"type_select": "Repeat type",
|
"type_select": "Repeat type",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user