Remove activate scene in automation editor (#22258)

This commit is contained in:
Simon Lamon 2024-11-20 17:02:15 +01:00 committed by GitHub
parent f7f936cb54
commit 6a337cc486
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 11 additions and 137 deletions

View File

@ -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 { 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 { 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 { 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";
@ -33,7 +32,6 @@ const SCHEMAS: { name: string; actions: Action[] }[] = [
{ name: "Service", actions: [HaServiceAction.defaultConfig] },
{ name: "Condition", actions: [HaConditionAction.defaultConfig] },
{ name: "Delay", actions: [HaDelayAction.defaultConfig] },
{ name: "Scene", actions: [HaSceneAction.defaultConfig] },
{ name: "Play media", actions: [HaPlayMediaAction.defaultConfig] },
{ name: "Wait", actions: [HaWaitAction.defaultConfig] },
{ name: "WaitForTrigger", actions: [HaWaitForTriggerAction.defaultConfig] },

View File

@ -11,7 +11,6 @@ import {
mdiFormatListNumbered,
mdiGestureDoubleTap,
mdiHandBackRight,
mdiPalette,
mdiPlay,
mdiRefresh,
mdiRoomService,
@ -27,7 +26,6 @@ export const ACTION_ICONS = {
delay: mdiTimerOutline,
event: mdiGestureDoubleTap,
play_media: mdiPlay,
activate_scene: mdiPalette,
service: mdiRoomService,
wait_template: mdiCodeBraces,
wait_for_trigger: mdiTrafficLight,

View File

@ -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 {
attributes: HassEntityAttributeBase & {
last_triggered: string;
@ -161,17 +151,6 @@ export interface DelayAction extends BaseAction {
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 {
wait_template: string;
timeout?: number;
@ -272,7 +251,6 @@ export type NonConditionAction =
| DeviceAction
| ServiceAction
| DelayAction
| SceneAction
| WaitAction
| WaitForTriggerAction
| RepeatAction
@ -298,7 +276,6 @@ export interface ActionTypes {
check_condition: Condition;
fire_event: EventAction;
device_action: DeviceAction;
activate_scene: SceneAction;
repeat: RepeatAction;
choose: ChooseAction;
if: IfAction;
@ -381,9 +358,6 @@ export const getActionType = (action: Action): ActionType => {
if ("device_id" in action) {
return "device_action";
}
if ("scene" in action) {
return "activate_scene";
}
if ("repeat" in action) {
return "repeat";
}
@ -413,9 +387,6 @@ export const getActionType = (action: Action): ActionType => {
}
if ("action" in action || "service" in action) {
if ("metadata" in action) {
if (is(action, activateSceneActionStruct)) {
return "activate_scene";
}
if (is(action, playMediaActionStruct)) {
return "play_media";
}
@ -447,6 +418,15 @@ export const migrateAutomationAction = (
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) {
for (const sequenceAction of (action as SequenceAction).sequence) {
migrateAutomationAction(sequenceAction);

View File

@ -28,7 +28,6 @@ import type {
ParallelAction,
PlayMediaAction,
RepeatAction,
SceneAction,
SequenceAction,
SetConversationResponseAction,
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") {
const config = action as PlayMediaAction;
const entityId = config.target?.entity_id || config.entity_id;

View File

@ -60,7 +60,6 @@ import {
import { haStyle } from "../../../../resources/styles";
import type { HomeAssistant } from "../../../../types";
import { showToast } from "../../../../util/toast";
import "./types/ha-automation-action-activate_scene";
import "./types/ha-automation-action-choose";
import "./types/ha-automation-action-condition";
import "./types/ha-automation-action-delay";
@ -81,8 +80,8 @@ export const getType = (action: Action | undefined) => {
if (!action) {
return undefined;
}
if ("action" in action || "scene" in action) {
return getActionType(action) as "activate_scene" | "action" | "play_media";
if ("action" in action) {
return getActionType(action) as "action" | "play_media";
}
if (["and", "or", "not"].some((key) => key in action)) {
return "condition" as const;

View File

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

View File

@ -3495,14 +3495,6 @@
"no_device": "Device action"
}
},
"activate_scene": {
"label": "Scene",
"scene": "Scene",
"description": {
"activate_scene": "Activate a scene",
"activate_scene_with_name": "Activate scene {name}"
}
},
"repeat": {
"label": "Repeat",
"type_select": "Repeat type",