Add show-automation-editor event for custom cards & panels (#26613)

* expose showAutomationEditor functionality in ha-panel-custom

* drop connectedCallback change (leftover from earlier test)

* enhance documentation for showAutomationEditor method

* Add automation editor mixin and event declaration for show-automation-editor
This commit is contained in:
Philipp Waller
2025-08-21 07:22:05 +02:00
committed by GitHub
parent e5585e13fe
commit feed58c33e
3 changed files with 43 additions and 0 deletions

View File

@@ -15,6 +15,16 @@ import { CONDITION_BUILDING_BLOCKS } from "./condition";
export const AUTOMATION_DEFAULT_MODE: (typeof MODES)[number] = "single";
export const AUTOMATION_DEFAULT_MAX = 10;
declare global {
interface HASSDomEvents {
/**
* Dispatched to open the automation editor.
* Used by custom cards/panels to trigger the editor view.
*/
"show-automation-editor": ShowAutomationEditorParams;
}
}
export interface AutomationEntity extends HassEntityBase {
attributes: HassEntityAttributeBase & {
id?: string;
@@ -546,3 +556,8 @@ export interface AutomationClipboard {
condition?: Condition;
action?: Action;
}
export interface ShowAutomationEditorParams {
data?: Partial<AutomationConfig>;
expanded?: boolean;
}

View File

@@ -0,0 +1,26 @@
import type { PropertyValues } from "lit";
import type { HASSDomEvent } from "../common/dom/fire_event";
import {
showAutomationEditor,
type ShowAutomationEditorParams,
} from "../data/automation";
import type { Constructor } from "../types";
import type { HassBaseEl } from "./hass-base-mixin";
export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
class extends superClass {
protected firstUpdated(changedProps: PropertyValues) {
super.firstUpdated(changedProps);
this.addEventListener("show-automation-editor", (ev) =>
this._handleShowAutomationEditor(
ev as HASSDomEvent<ShowAutomationEditorParams>
)
);
}
private _handleShowAutomationEditor(
ev: HASSDomEvent<ShowAutomationEditorParams>
) {
showAutomationEditor(ev.detail.data, ev.detail.expanded);
}
};

View File

@@ -8,6 +8,7 @@ import { HassBaseEl } from "./hass-base-mixin";
import { loggingMixin } from "./logging-mixin";
import { contextMixin } from "./context-mixin";
import MoreInfoMixin from "./more-info-mixin";
import AutomationEditorMixin from "./automation-editor-mixin";
import ActionMixin from "./action-mixin";
import NotificationMixin from "./notification-mixin";
import { panelTitleMixin } from "./panel-title-mixin";
@@ -26,6 +27,7 @@ export class HassElement extends ext(HassBaseEl, [
TranslationsMixin,
StateDisplayMixin,
MoreInfoMixin,
AutomationEditorMixin,
ActionMixin,
SidebarMixin,
DisconnectToastMixin,