mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-16 13:56:35 +00:00
Automation/Script editor add settings,category overflow actions (#23272)
* Add settings, category actions * Add script category and settings actions * Correct overflow actions order * Use consume instead of subscribe
This commit is contained in:
parent
69ed736080
commit
d2ec24f32a
@ -1,5 +1,6 @@
|
|||||||
import "@material/mwc-button";
|
import "@material/mwc-button";
|
||||||
import {
|
import {
|
||||||
|
mdiCog,
|
||||||
mdiContentDuplicate,
|
mdiContentDuplicate,
|
||||||
mdiContentSave,
|
mdiContentSave,
|
||||||
mdiDebugStepOver,
|
mdiDebugStepOver,
|
||||||
@ -13,6 +14,7 @@ import {
|
|||||||
mdiRenameBox,
|
mdiRenameBox,
|
||||||
mdiRobotConfused,
|
mdiRobotConfused,
|
||||||
mdiStopCircleOutline,
|
mdiStopCircleOutline,
|
||||||
|
mdiTag,
|
||||||
mdiTransitConnection,
|
mdiTransitConnection,
|
||||||
} from "@mdi/js";
|
} from "@mdi/js";
|
||||||
import type { UnsubscribeFunc } from "home-assistant-js-websocket";
|
import type { UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||||
@ -20,6 +22,7 @@ import type { CSSResultGroup, PropertyValues, TemplateResult } from "lit";
|
|||||||
import { LitElement, css, html, nothing } from "lit";
|
import { LitElement, css, html, nothing } from "lit";
|
||||||
import { property, state } from "lit/decorators";
|
import { property, state } from "lit/decorators";
|
||||||
import { classMap } from "lit/directives/class-map";
|
import { classMap } from "lit/directives/class-map";
|
||||||
|
import { consume } from "@lit-labs/context";
|
||||||
import { fireEvent } from "../../../common/dom/fire_event";
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
import { navigate } from "../../../common/navigate";
|
import { navigate } from "../../../common/navigate";
|
||||||
import { computeRTL } from "../../../common/util/compute_rtl";
|
import { computeRTL } from "../../../common/util/compute_rtl";
|
||||||
@ -49,7 +52,10 @@ import {
|
|||||||
import { substituteBlueprint } from "../../../data/blueprint";
|
import { substituteBlueprint } from "../../../data/blueprint";
|
||||||
import { validateConfig } from "../../../data/config";
|
import { validateConfig } from "../../../data/config";
|
||||||
import { UNAVAILABLE } from "../../../data/entity";
|
import { UNAVAILABLE } from "../../../data/entity";
|
||||||
import { fetchEntityRegistry } from "../../../data/entity_registry";
|
import {
|
||||||
|
fetchEntityRegistry,
|
||||||
|
type EntityRegistryEntry,
|
||||||
|
} from "../../../data/entity_registry";
|
||||||
import {
|
import {
|
||||||
showAlertDialog,
|
showAlertDialog,
|
||||||
showConfirmationDialog,
|
showConfirmationDialog,
|
||||||
@ -64,7 +70,11 @@ import { showAutomationModeDialog } from "./automation-mode-dialog/show-dialog-a
|
|||||||
import { showAutomationRenameDialog } from "./automation-rename-dialog/show-dialog-automation-rename";
|
import { showAutomationRenameDialog } from "./automation-rename-dialog/show-dialog-automation-rename";
|
||||||
import "./blueprint-automation-editor";
|
import "./blueprint-automation-editor";
|
||||||
import "./manual-automation-editor";
|
import "./manual-automation-editor";
|
||||||
|
import { showMoreInfoDialog } from "../../../dialogs/more-info/show-ha-more-info-dialog";
|
||||||
|
import { showAssignCategoryDialog } from "../category/show-dialog-assign-category";
|
||||||
import { PreventUnsavedMixin } from "../../../mixins/prevent-unsaved-mixin";
|
import { PreventUnsavedMixin } from "../../../mixins/prevent-unsaved-mixin";
|
||||||
|
import { fullEntitiesContext } from "../../../data/context";
|
||||||
|
import { transform } from "../../../common/decorators/transform";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface HTMLElementTagNameMap {
|
interface HTMLElementTagNameMap {
|
||||||
@ -118,6 +128,15 @@ export class HaAutomationEditor extends PreventUnsavedMixin(
|
|||||||
|
|
||||||
@state() private _blueprintConfig?: BlueprintAutomationConfig;
|
@state() private _blueprintConfig?: BlueprintAutomationConfig;
|
||||||
|
|
||||||
|
@consume({ context: fullEntitiesContext, subscribe: true })
|
||||||
|
@transform<EntityRegistryEntry | undefined, EntityRegistryEntry[]>({
|
||||||
|
transformer: function (this: HaAutomationEditor, value) {
|
||||||
|
return value.find(({ entity_id }) => entity_id === this._entityId);
|
||||||
|
},
|
||||||
|
watch: ["_entityId"],
|
||||||
|
})
|
||||||
|
private _registryEntry?: EntityRegistryEntry;
|
||||||
|
|
||||||
private _configSubscriptions: Record<
|
private _configSubscriptions: Record<
|
||||||
string,
|
string,
|
||||||
(config?: AutomationConfig) => void
|
(config?: AutomationConfig) => void
|
||||||
@ -172,6 +191,28 @@ export class HaAutomationEditor extends PreventUnsavedMixin(
|
|||||||
></ha-svg-icon>
|
></ha-svg-icon>
|
||||||
</ha-list-item>
|
</ha-list-item>
|
||||||
|
|
||||||
|
<ha-list-item
|
||||||
|
graphic="icon"
|
||||||
|
.disabled=${!stateObj}
|
||||||
|
@click=${this._showSettings}
|
||||||
|
>
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.picker.show_settings"
|
||||||
|
)}
|
||||||
|
<ha-svg-icon slot="graphic" .path=${mdiCog}></ha-svg-icon>
|
||||||
|
</ha-list-item>
|
||||||
|
|
||||||
|
<ha-list-item
|
||||||
|
graphic="icon"
|
||||||
|
.disabled=${!stateObj}
|
||||||
|
@click=${this._editCategory}
|
||||||
|
>
|
||||||
|
${this.hass.localize(
|
||||||
|
`ui.panel.config.scene.picker.${this._registryEntry?.categories?.automation ? "edit_category" : "assign_category"}`
|
||||||
|
)}
|
||||||
|
<ha-svg-icon slot="graphic" .path=${mdiTag}></ha-svg-icon>
|
||||||
|
</ha-list-item>
|
||||||
|
|
||||||
<ha-list-item
|
<ha-list-item
|
||||||
graphic="icon"
|
graphic="icon"
|
||||||
.disabled=${!stateObj}
|
.disabled=${!stateObj}
|
||||||
@ -580,6 +621,31 @@ export class HaAutomationEditor extends PreventUnsavedMixin(
|
|||||||
fireEvent(this, "hass-more-info", { entityId: this._entityId });
|
fireEvent(this, "hass-more-info", { entityId: this._entityId });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _showSettings() {
|
||||||
|
showMoreInfoDialog(this, {
|
||||||
|
entityId: this._entityId!,
|
||||||
|
view: "settings",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private _editCategory() {
|
||||||
|
if (!this._registryEntry) {
|
||||||
|
showAlertDialog(this, {
|
||||||
|
title: this.hass.localize(
|
||||||
|
"ui.panel.config.scene.picker.no_category_support"
|
||||||
|
),
|
||||||
|
text: this.hass.localize(
|
||||||
|
"ui.panel.config.scene.picker.no_category_entity_reg"
|
||||||
|
),
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
showAssignCategoryDialog(this, {
|
||||||
|
scope: "automation",
|
||||||
|
entityReg: this._registryEntry,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private async _showTrace() {
|
private async _showTrace() {
|
||||||
if (this._config?.id) {
|
if (this._config?.id) {
|
||||||
const result = await this._confirmUnsavedChanged();
|
const result = await this._confirmUnsavedChanged();
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import "@material/mwc-button";
|
import "@material/mwc-button";
|
||||||
import {
|
import {
|
||||||
|
mdiCog,
|
||||||
mdiContentDuplicate,
|
mdiContentDuplicate,
|
||||||
mdiContentSave,
|
mdiContentSave,
|
||||||
mdiDebugStepOver,
|
mdiDebugStepOver,
|
||||||
@ -12,12 +13,14 @@ import {
|
|||||||
mdiPlaylistEdit,
|
mdiPlaylistEdit,
|
||||||
mdiRenameBox,
|
mdiRenameBox,
|
||||||
mdiRobotConfused,
|
mdiRobotConfused,
|
||||||
|
mdiTag,
|
||||||
mdiTransitConnection,
|
mdiTransitConnection,
|
||||||
} from "@mdi/js";
|
} from "@mdi/js";
|
||||||
import type { CSSResultGroup, PropertyValues, TemplateResult } from "lit";
|
import type { CSSResultGroup, PropertyValues, TemplateResult } from "lit";
|
||||||
import { LitElement, css, html, nothing } from "lit";
|
import { LitElement, css, html, nothing } from "lit";
|
||||||
import { property, query, state } from "lit/decorators";
|
import { property, query, state } from "lit/decorators";
|
||||||
import { classMap } from "lit/directives/class-map";
|
import { classMap } from "lit/directives/class-map";
|
||||||
|
import { consume } from "@lit-labs/context";
|
||||||
import { fireEvent } from "../../../common/dom/fire_event";
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
import { navigate } from "../../../common/navigate";
|
import { navigate } from "../../../common/navigate";
|
||||||
import { slugify } from "../../../common/string/slugify";
|
import { slugify } from "../../../common/string/slugify";
|
||||||
@ -44,7 +47,10 @@ import {
|
|||||||
showScriptEditor,
|
showScriptEditor,
|
||||||
triggerScript,
|
triggerScript,
|
||||||
} from "../../../data/script";
|
} from "../../../data/script";
|
||||||
import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box";
|
import {
|
||||||
|
showAlertDialog,
|
||||||
|
showConfirmationDialog,
|
||||||
|
} from "../../../dialogs/generic/show-dialog-box";
|
||||||
import { showMoreInfoDialog } from "../../../dialogs/more-info/show-ha-more-info-dialog";
|
import { showMoreInfoDialog } from "../../../dialogs/more-info/show-ha-more-info-dialog";
|
||||||
import "../../../layouts/hass-subpage";
|
import "../../../layouts/hass-subpage";
|
||||||
import { KeyboardShortcutMixin } from "../../../mixins/keyboard-shortcut-mixin";
|
import { KeyboardShortcutMixin } from "../../../mixins/keyboard-shortcut-mixin";
|
||||||
@ -57,10 +63,14 @@ import "./blueprint-script-editor";
|
|||||||
import "./manual-script-editor";
|
import "./manual-script-editor";
|
||||||
import type { HaManualScriptEditor } from "./manual-script-editor";
|
import type { HaManualScriptEditor } from "./manual-script-editor";
|
||||||
import { substituteBlueprint } from "../../../data/blueprint";
|
import { substituteBlueprint } from "../../../data/blueprint";
|
||||||
|
import { SubscribeMixin } from "../../../mixins/subscribe-mixin";
|
||||||
|
import { showAssignCategoryDialog } from "../category/show-dialog-assign-category";
|
||||||
import { PreventUnsavedMixin } from "../../../mixins/prevent-unsaved-mixin";
|
import { PreventUnsavedMixin } from "../../../mixins/prevent-unsaved-mixin";
|
||||||
|
import { fullEntitiesContext } from "../../../data/context";
|
||||||
|
import { transform } from "../../../common/decorators/transform";
|
||||||
|
|
||||||
export class HaScriptEditor extends PreventUnsavedMixin(
|
export class HaScriptEditor extends SubscribeMixin(
|
||||||
KeyboardShortcutMixin(LitElement)
|
PreventUnsavedMixin(KeyboardShortcutMixin(LitElement))
|
||||||
) {
|
) {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
@ -90,6 +100,15 @@ export class HaScriptEditor extends PreventUnsavedMixin(
|
|||||||
|
|
||||||
@state() private _readOnly = false;
|
@state() private _readOnly = false;
|
||||||
|
|
||||||
|
@consume({ context: fullEntitiesContext, subscribe: true })
|
||||||
|
@transform<EntityRegistryEntry | undefined, EntityRegistryEntry[]>({
|
||||||
|
transformer: function (this: HaScriptEditor, value) {
|
||||||
|
return value.find(({ entity_id }) => entity_id === this._entityId);
|
||||||
|
},
|
||||||
|
watch: ["_entityId"],
|
||||||
|
})
|
||||||
|
private _registryEntry?: EntityRegistryEntry;
|
||||||
|
|
||||||
@query("manual-script-editor")
|
@query("manual-script-editor")
|
||||||
private _manualEditor?: HaManualScriptEditor;
|
private _manualEditor?: HaManualScriptEditor;
|
||||||
|
|
||||||
@ -143,6 +162,28 @@ export class HaScriptEditor extends PreventUnsavedMixin(
|
|||||||
></ha-svg-icon>
|
></ha-svg-icon>
|
||||||
</ha-list-item>
|
</ha-list-item>
|
||||||
|
|
||||||
|
<ha-list-item
|
||||||
|
graphic="icon"
|
||||||
|
.disabled=${!stateObj}
|
||||||
|
@click=${this._showSettings}
|
||||||
|
>
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.picker.show_settings"
|
||||||
|
)}
|
||||||
|
<ha-svg-icon slot="graphic" .path=${mdiCog}></ha-svg-icon>
|
||||||
|
</ha-list-item>
|
||||||
|
|
||||||
|
<ha-list-item
|
||||||
|
graphic="icon"
|
||||||
|
.disabled=${!stateObj}
|
||||||
|
@click=${this._editCategory}
|
||||||
|
>
|
||||||
|
${this.hass.localize(
|
||||||
|
`ui.panel.config.scene.picker.${this._registryEntry?.categories?.script ? "edit_category" : "assign_category"}`
|
||||||
|
)}
|
||||||
|
<ha-svg-icon slot="graphic" .path=${mdiTag}></ha-svg-icon>
|
||||||
|
</ha-list-item>
|
||||||
|
|
||||||
<ha-list-item
|
<ha-list-item
|
||||||
graphic="icon"
|
graphic="icon"
|
||||||
.disabled=${!this.scriptId}
|
.disabled=${!this.scriptId}
|
||||||
@ -542,6 +583,31 @@ export class HaScriptEditor extends PreventUnsavedMixin(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _showSettings() {
|
||||||
|
showMoreInfoDialog(this, {
|
||||||
|
entityId: this._entityId!,
|
||||||
|
view: "settings",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private _editCategory() {
|
||||||
|
if (!this._registryEntry) {
|
||||||
|
showAlertDialog(this, {
|
||||||
|
title: this.hass.localize(
|
||||||
|
"ui.panel.config.scene.picker.no_category_support"
|
||||||
|
),
|
||||||
|
text: this.hass.localize(
|
||||||
|
"ui.panel.config.scene.picker.no_category_entity_reg"
|
||||||
|
),
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
showAssignCategoryDialog(this, {
|
||||||
|
scope: "script",
|
||||||
|
entityReg: this._registryEntry,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private _computeEntityIdFromAlias(alias: string) {
|
private _computeEntityIdFromAlias(alias: string) {
|
||||||
const aliasSlugify = slugify(alias);
|
const aliasSlugify = slugify(alias);
|
||||||
let id = aliasSlugify;
|
let id = aliasSlugify;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user