@@ -27,11 +27,9 @@ import { css, html, LitElement, nothing } from "lit";
2727import { customElement , property , query , state } from "lit/decorators" ;
2828import { classMap } from "lit/directives/class-map" ;
2929import { UndoRedoController } from "../../../common/controllers/undo-redo-controller" ;
30- import { transform } from "../../../common/decorators/transform" ;
3130import { fireEvent } from "../../../common/dom/fire_event" ;
3231import { goBack , navigate } from "../../../common/navigate" ;
3332import { promiseTimeout } from "../../../common/util/promise-timeout" ;
34- import { afterNextRender } from "../../../common/util/render-status" ;
3533import "../../../components/ha-button" ;
3634import "../../../components/ha-dropdown" ;
3735import "../../../components/ha-dropdown-item" ;
@@ -72,27 +70,24 @@ import {
7270 showAlertDialog ,
7371 showConfirmationDialog ,
7472} from "../../../dialogs/generic/show-dialog-box" ;
75- import { showMoreInfoDialog } from "../../../dialogs/more-info/show-ha-more-info-dialog" ;
7673import "../../../layouts/hass-subpage" ;
7774import { KeyboardShortcutMixin } from "../../../mixins/keyboard-shortcut-mixin" ;
7875import { PreventUnsavedMixin } from "../../../mixins/prevent-unsaved-mixin" ;
7976import { haStyle } from "../../../resources/styles" ;
8077import type {
8178 Entries ,
82- HomeAssistant ,
83- Route ,
8479 ValueChangedEvent ,
8580} from "../../../types" ;
8681import { isMac } from "../../../util/is_mac" ;
8782import { showToast } from "../../../util/toast" ;
8883import { showAssignCategoryDialog } from "../category/show-dialog-assign-category" ;
8984import { showAutomationModeDialog } from "./automation-mode-dialog/show-dialog-automation-mode" ;
9085import {
91- type EntityRegistryUpdate ,
9286 showAutomationSaveDialog ,
9387} from "./automation-save-dialog/show-dialog-automation-save" ;
9488import { showAutomationSaveTimeoutDialog } from "./automation-save-timeout-dialog/show-dialog-automation-save-timeout" ;
9589import "./blueprint-automation-editor" ;
90+ import { AutomationScriptEditorMixin } from "./ha-automation-script-editor-mixin" ;
9691import "./manual-automation-editor" ;
9792import type { HaManualAutomationEditor } from "./manual-automation-editor" ;
9893import type { HaDropdownSelectEvent } from "../../../components/ha-dropdown" ;
@@ -119,53 +114,13 @@ declare global {
119114}
120115
121116@customElement ( "ha-automation-editor" )
122- export class HaAutomationEditor extends PreventUnsavedMixin (
123- KeyboardShortcutMixin ( LitElement )
117+ export class HaAutomationEditor extends AutomationScriptEditorMixin < AutomationConfig > (
118+ PreventUnsavedMixin ( KeyboardShortcutMixin ( LitElement ) )
124119) {
125- @property ( { attribute : false } ) public hass ! : HomeAssistant ;
126-
127120 @property ( { attribute : false } ) public automationId : string | null = null ;
128121
129- @property ( { attribute : false } ) public entityId : string | null = null ;
130-
131122 @property ( { attribute : false } ) public automations ! : AutomationEntity [ ] ;
132123
133- @property ( { attribute : "is-wide" , type : Boolean } ) public isWide = false ;
134-
135- @property ( { type : Boolean } ) public narrow = false ;
136-
137- @property ( { attribute : false } ) public route ! : Route ;
138-
139- @state ( ) private _config ?: AutomationConfig ;
140-
141- @state ( ) private _dirty = false ;
142-
143- @state ( ) private _errors ?: string ;
144-
145- @state ( ) private _yamlErrors ?: string ;
146-
147- @state ( ) private _entityId ?: string ;
148-
149- @state ( ) private _mode : "gui" | "yaml" = "gui" ;
150-
151- @state ( ) private _readOnly = false ;
152-
153- @state ( ) private _validationErrors ?: ( string | TemplateResult ) [ ] ;
154-
155- @state ( ) private _blueprintConfig ?: BlueprintAutomationConfig ;
156-
157- @state ( )
158- @consume ( { context : fullEntitiesContext , subscribe : true } )
159- @transform < EntityRegistryEntry [ ] , EntityRegistryEntry > ( {
160- transformer : function ( this : HaAutomationEditor , value ) {
161- return value . find ( ( { entity_id } ) => entity_id === this . _entityId ) ;
162- } ,
163- watch : [ "_entityId" ] ,
164- } )
165- private _registryEntry ?: EntityRegistryEntry ;
166-
167- @state ( ) private _saving = false ;
168-
169124 @state ( )
170125 @consume ( { context : fullEntitiesContext , subscribe : true } )
171126 _entityRegistry ! : EntityRegistryEntry [ ] ;
@@ -180,14 +135,8 @@ export class HaAutomationEditor extends PreventUnsavedMixin(
180135
181136 private _configSubscriptionsId = 1 ;
182137
183- private _entityRegistryUpdate ?: EntityRegistryUpdate ;
184-
185138 private _newAutomationId ?: string ;
186139
187- private _entityRegCreated ?: (
188- value : PromiseLike < EntityRegistryEntry > | EntityRegistryEntry
189- ) => void ;
190-
191140 private _undoRedoController = new UndoRedoController < AutomationConfig > ( this , {
192141 apply : ( config ) => this . _applyUndoRedo ( config ) ,
193142 currentConfig : ( ) => this . _config ! ,
@@ -780,13 +729,6 @@ export class HaAutomationEditor extends PreventUnsavedMixin(
780729 fireEvent ( this , "hass-more-info" , { entityId : this . _entityId } ) ;
781730 }
782731
783- private _showSettings ( ) {
784- showMoreInfoDialog ( this , {
785- entityId : this . _entityId ! ,
786- view : "settings" ,
787- } ) ;
788- }
789-
790732 private _editCategory ( ) {
791733 if ( ! this . _registryEntry ) {
792734 showAlertDialog ( this , {
@@ -861,7 +803,7 @@ export class HaAutomationEditor extends PreventUnsavedMixin(
861803 this . _errors = undefined ;
862804 }
863805
864- private async _confirmUnsavedChanged ( ) : Promise < boolean > {
806+ protected async _confirmUnsavedChanged ( ) : Promise < boolean > {
865807 if ( ! this . _dirty ) {
866808 return true ;
867809 }
@@ -906,13 +848,6 @@ export class HaAutomationEditor extends PreventUnsavedMixin(
906848 } ) ;
907849 }
908850
909- private _backTapped = async ( ) => {
910- const result = await this . _confirmUnsavedChanged ( ) ;
911- if ( result ) {
912- afterNextRender ( ( ) => goBack ( "/config" ) ) ;
913- }
914- } ;
915-
916851 private async _takeControl ( ) {
917852 const config = this . _config as BlueprintAutomationConfig ;
918853
@@ -943,21 +878,6 @@ export class HaAutomationEditor extends PreventUnsavedMixin(
943878 }
944879 }
945880
946- private _revertBlueprint ( ) {
947- this . _config = this . _blueprintConfig ;
948- if ( this . _mode === "yaml" ) {
949- this . renderRoot . querySelector ( "ha-yaml-editor" ) ?. setValue ( this . _config ) ;
950- }
951- this . _blueprintConfig = undefined ;
952- this . _readOnly = false ;
953- }
954-
955- private _takeControlSave ( ) {
956- this . _readOnly = false ;
957- this . _dirty = true ;
958- this . _blueprintConfig = undefined ;
959- }
960-
961881 private async _duplicate ( ) {
962882 const result = this . _readOnly
963883 ? await showConfirmationDialog ( this , {
@@ -1001,28 +921,6 @@ export class HaAutomationEditor extends PreventUnsavedMixin(
1001921 }
1002922 }
1003923
1004- private async _switchUiMode ( ) {
1005- if ( this . _yamlErrors ) {
1006- const result = await showConfirmationDialog ( this , {
1007- text : html `${ this . hass . localize (
1008- "ui.panel.config.automation.editor.switch_ui_yaml_error"
1009- ) } <br / > <br / > ${ this . _yamlErrors } `,
1010- confirmText : this . hass ! . localize ( "ui.common.continue" ) ,
1011- destructive : true ,
1012- dismissText : this . hass ! . localize ( "ui.common.cancel" ) ,
1013- } ) ;
1014- if ( ! result ) {
1015- return ;
1016- }
1017- }
1018- this . _yamlErrors = undefined ;
1019- this . _mode = "gui" ;
1020- }
1021-
1022- private _switchYamlMode ( ) {
1023- this . _mode = "yaml" ;
1024- }
1025-
1026924 private async _promptAutomationAlias ( ) : Promise < boolean > {
1027925 return new Promise ( ( resolve ) => {
1028926 showAutomationSaveDialog ( this , {
@@ -1173,14 +1071,6 @@ export class HaAutomationEditor extends PreventUnsavedMixin(
11731071 } ;
11741072 }
11751073
1176- protected get isDirty ( ) {
1177- return this . _dirty ;
1178- }
1179-
1180- protected async promptDiscardChanges ( ) {
1181- return this . _confirmUnsavedChanged ( ) ;
1182- }
1183-
11841074 // @ts -ignore
11851075 private _collapseAll ( ) {
11861076 this . _manualEditor ?. collapseAll ( ) ;
0 commit comments