mirror of
https://github.com/home-assistant/frontend.git
synced 2025-12-09 09:37:38 +00:00
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:
@@ -15,6 +15,16 @@ import { CONDITION_BUILDING_BLOCKS } from "./condition";
|
|||||||
export const AUTOMATION_DEFAULT_MODE: (typeof MODES)[number] = "single";
|
export const AUTOMATION_DEFAULT_MODE: (typeof MODES)[number] = "single";
|
||||||
export const AUTOMATION_DEFAULT_MAX = 10;
|
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 {
|
export interface AutomationEntity extends HassEntityBase {
|
||||||
attributes: HassEntityAttributeBase & {
|
attributes: HassEntityAttributeBase & {
|
||||||
id?: string;
|
id?: string;
|
||||||
@@ -546,3 +556,8 @@ export interface AutomationClipboard {
|
|||||||
condition?: Condition;
|
condition?: Condition;
|
||||||
action?: Action;
|
action?: Action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ShowAutomationEditorParams {
|
||||||
|
data?: Partial<AutomationConfig>;
|
||||||
|
expanded?: boolean;
|
||||||
|
}
|
||||||
|
|||||||
26
src/state/automation-editor-mixin.ts
Normal file
26
src/state/automation-editor-mixin.ts
Normal 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);
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -8,6 +8,7 @@ import { HassBaseEl } from "./hass-base-mixin";
|
|||||||
import { loggingMixin } from "./logging-mixin";
|
import { loggingMixin } from "./logging-mixin";
|
||||||
import { contextMixin } from "./context-mixin";
|
import { contextMixin } from "./context-mixin";
|
||||||
import MoreInfoMixin from "./more-info-mixin";
|
import MoreInfoMixin from "./more-info-mixin";
|
||||||
|
import AutomationEditorMixin from "./automation-editor-mixin";
|
||||||
import ActionMixin from "./action-mixin";
|
import ActionMixin from "./action-mixin";
|
||||||
import NotificationMixin from "./notification-mixin";
|
import NotificationMixin from "./notification-mixin";
|
||||||
import { panelTitleMixin } from "./panel-title-mixin";
|
import { panelTitleMixin } from "./panel-title-mixin";
|
||||||
@@ -26,6 +27,7 @@ export class HassElement extends ext(HassBaseEl, [
|
|||||||
TranslationsMixin,
|
TranslationsMixin,
|
||||||
StateDisplayMixin,
|
StateDisplayMixin,
|
||||||
MoreInfoMixin,
|
MoreInfoMixin,
|
||||||
|
AutomationEditorMixin,
|
||||||
ActionMixin,
|
ActionMixin,
|
||||||
SidebarMixin,
|
SidebarMixin,
|
||||||
DisconnectToastMixin,
|
DisconnectToastMixin,
|
||||||
|
|||||||
Reference in New Issue
Block a user