From 583501e3a1a0815c2350c3488e1453b4672f7dde Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Tue, 14 Nov 2023 18:22:32 +0100 Subject: [PATCH 01/10] Add configuration to default dashboard --- .../common/generate-lovelace-config.ts | 18 ++++++++++++++++-- .../original-states-dashboard-strategy.ts | 8 +++++--- .../original-states-view-strategy.ts | 15 ++++++++++++--- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/panels/lovelace/common/generate-lovelace-config.ts b/src/panels/lovelace/common/generate-lovelace-config.ts index 0a37fd56e69f..27aa1f885017 100644 --- a/src/panels/lovelace/common/generate-lovelace-config.ts +++ b/src/panels/lovelace/common/generate-lovelace-config.ts @@ -446,7 +446,10 @@ export const generateDefaultViewConfig = ( entityEntries: HomeAssistant["entities"], entities: HassEntities, localize: LocalizeFunc, - energyPrefs?: EnergyPreferences + energyPrefs?: EnergyPreferences, + hiddenAreas?: string[], + hideEntitiesWithoutAreas?: boolean, + hideEnergy?: boolean ): LovelaceViewConfig => { const states = computeDefaultViewStates(entities, entityEntries); const path = "default_view"; @@ -469,6 +472,17 @@ export const generateDefaultViewConfig = ( states ); + if (hiddenAreas) { + for (const area of hiddenAreas) { + splittedByAreaDevice.areasWithEntities[area] = []; + } + } + + if (hideEntitiesWithoutAreas) { + splittedByAreaDevice.devicesWithEntities = {}; + splittedByAreaDevice.otherEntities = {}; + } + const splittedByGroups = splitByGroups(splittedByAreaDevice.otherEntities); splittedByGroups.groups.sort( (gr1, gr2) => groupOrders[gr1.entity_id] - groupOrders[gr2.entity_id] @@ -553,7 +567,7 @@ export const generateDefaultViewConfig = ( let energyCard: LovelaceCardConfig | undefined; - if (energyPrefs) { + if (energyPrefs && !hideEnergy) { // Distribution card requires the grid to be configured const grid = energyPrefs.energy_sources.find( (source) => source.type === "grid" diff --git a/src/panels/lovelace/strategies/original-states-dashboard-strategy.ts b/src/panels/lovelace/strategies/original-states-dashboard-strategy.ts index 7dfaec41a819..c8717140b5aa 100644 --- a/src/panels/lovelace/strategies/original-states-dashboard-strategy.ts +++ b/src/panels/lovelace/strategies/original-states-dashboard-strategy.ts @@ -1,20 +1,22 @@ import { ReactiveElement } from "lit"; import { customElement } from "lit/decorators"; import { HomeAssistant } from "../../../types"; -import { LovelaceStrategyConfig } from "../../../data/lovelace/config/strategy"; +import { OriginalStatesViewStrategyConfig } from "./original-states-view-strategy"; import { LovelaceConfig } from "../../../data/lovelace/config/types"; +type OriginalStatesStrategyConfig = OriginalStatesViewStrategyConfig; + @customElement("original-states-dashboard-strategy") export class OriginalStatesDashboardStrategy extends ReactiveElement { static async generate( - _config: LovelaceStrategyConfig, + config: OriginalStatesStrategyConfig, hass: HomeAssistant ): Promise { return { title: hass.config.location_name, views: [ { - strategy: { type: "original-states" }, + strategy: config, }, ], }; diff --git a/src/panels/lovelace/strategies/original-states-view-strategy.ts b/src/panels/lovelace/strategies/original-states-view-strategy.ts index 05cb1ecd2b2e..fe3c6611880b 100644 --- a/src/panels/lovelace/strategies/original-states-view-strategy.ts +++ b/src/panels/lovelace/strategies/original-states-view-strategy.ts @@ -3,15 +3,21 @@ import { ReactiveElement } from "lit"; import { customElement } from "lit/decorators"; import { isComponentLoaded } from "../../../common/config/is_component_loaded"; import { getEnergyPreferences } from "../../../data/energy"; -import { LovelaceStrategyConfig } from "../../../data/lovelace/config/strategy"; import { LovelaceViewConfig } from "../../../data/lovelace/config/view"; import { HomeAssistant } from "../../../types"; import { generateDefaultViewConfig } from "../common/generate-lovelace-config"; +export type OriginalStatesViewStrategyConfig = { + type: "original-states"; + hidden_areas?: string[]; + hide_entities_without_area?: boolean; + hide_energy?: boolean; +}; + @customElement("original-states-view-strategy") export class OriginalStatesViewStrategy extends ReactiveElement { static async generate( - _config: LovelaceStrategyConfig, + config: OriginalStatesViewStrategyConfig, hass: HomeAssistant ): Promise { if (hass.config.state === STATE_NOT_RUNNING) { @@ -42,7 +48,10 @@ export class OriginalStatesViewStrategy extends ReactiveElement { hass.entities, hass.states, localize, - energyPrefs + energyPrefs, + config.hidden_areas, + config.hide_entities_without_area, + config.hide_energy ); // Add map of geo locations to default view if loaded From b160f1906d23ff4b4b30b4067ff67d1a543c9e02 Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Wed, 13 Sep 2023 12:05:53 +0200 Subject: [PATCH 02/10] Add strategy editor rename clean function Fix types --- .../hui-dashboard-strategy-element-editor.ts | 30 ++++ ...iginal-states-dashboard-strategy-editor.ts | 75 ++++++++++ .../lovelace/editor/hui-element-editor.ts | 8 +- src/panels/lovelace/hui-root.ts | 17 ++- .../dialog-dashboard-strategy-editor.ts | 129 ++++++++++++++++++ .../show-dialog-dashboard-strategy-editor.ts | 21 +++ .../lovelace/strategies/get-strategy.ts | 11 +- .../lovelace/strategies/legacy-strategy.ts | 14 ++ .../original-states-dashboard-strategy.ts | 17 ++- src/panels/lovelace/strategies/types.ts | 6 + 10 files changed, 311 insertions(+), 17 deletions(-) create mode 100644 src/panels/lovelace/editor/dashboard-strategy-editor/hui-dashboard-strategy-element-editor.ts create mode 100644 src/panels/lovelace/editor/dashboard-strategy-editor/hui-original-states-dashboard-strategy-editor.ts create mode 100644 src/panels/lovelace/strategies/device-registry-detail/dialog-dashboard-strategy-editor.ts create mode 100644 src/panels/lovelace/strategies/device-registry-detail/show-dialog-dashboard-strategy-editor.ts diff --git a/src/panels/lovelace/editor/dashboard-strategy-editor/hui-dashboard-strategy-element-editor.ts b/src/panels/lovelace/editor/dashboard-strategy-editor/hui-dashboard-strategy-element-editor.ts new file mode 100644 index 000000000000..69984ec1096d --- /dev/null +++ b/src/panels/lovelace/editor/dashboard-strategy-editor/hui-dashboard-strategy-element-editor.ts @@ -0,0 +1,30 @@ +import { customElement } from "lit/decorators"; +import { LovelaceDashboardStrategyConfig } from "../../../../data/lovelace/config/types"; +import { getLovelaceStrategy } from "../../strategies/get-strategy"; +import { LovelaceStrategyEditor } from "../../strategies/types"; +import { HuiElementEditor } from "../hui-element-editor"; + +@customElement("hui-dashboard-strategy-element-editor") +export class HuiDashboardStrategyElementEditor extends HuiElementEditor { + protected async getConfigElement(): Promise< + LovelaceStrategyEditor | undefined + > { + const elClass = await getLovelaceStrategy( + "dashboard", + this.configElementType! + ); + + // Check if a GUI editor exists + if (elClass && elClass.getConfigElement) { + return elClass.getConfigElement(); + } + + return undefined; + } +} + +declare global { + interface HTMLElementTagNameMap { + "hui-dashboard-strategy-element-editor": HuiDashboardStrategyElementEditor; + } +} diff --git a/src/panels/lovelace/editor/dashboard-strategy-editor/hui-original-states-dashboard-strategy-editor.ts b/src/panels/lovelace/editor/dashboard-strategy-editor/hui-original-states-dashboard-strategy-editor.ts new file mode 100644 index 000000000000..d411ce5af9c2 --- /dev/null +++ b/src/panels/lovelace/editor/dashboard-strategy-editor/hui-original-states-dashboard-strategy-editor.ts @@ -0,0 +1,75 @@ +import { html, LitElement, nothing } from "lit"; +import { customElement, property, state } from "lit/decorators"; +import { fireEvent } from "../../../../common/dom/fire_event"; +import "../../../../components/ha-form/ha-form"; +import type { + HaFormSchema, + SchemaUnion, +} from "../../../../components/ha-form/types"; +import type { HomeAssistant } from "../../../../types"; +import { OriginalStatesDashboardStrategyConfig } from "../../strategies/original-states-dashboard-strategy"; +import { LovelaceStrategyEditor } from "../../strategies/types"; + +const SCHEMA = [ + { + name: "no_area_group", + selector: { + boolean: {}, + }, + }, +] as const satisfies readonly HaFormSchema[]; + +@customElement("hui-original-states-dashboard-strategy-editor") +export class HuiOriginalStatesDashboarStrategyEditor + extends LitElement + implements LovelaceStrategyEditor +{ + @property({ attribute: false }) public hass?: HomeAssistant; + + @state() + private _config?: OriginalStatesDashboardStrategyConfig; + + public setConfig(config: OriginalStatesDashboardStrategyConfig): void { + this._config = config; + } + + protected render() { + if (!this.hass || !this._config) { + return nothing; + } + + const data = this._config; + + return html` + + `; + } + + private _valueChanged(ev: CustomEvent): void { + const config = ev.detail.value; + fireEvent(this, "config-changed", { config }); + } + + private _computeLabelCallback = (schema: SchemaUnion) => { + switch (schema.name) { + case "no_area_group": + return "Do not group by area"; + default: + return this.hass!.localize( + `ui.panel.lovelace.editor.card.generic.${schema.name}` + ); + } + }; +} + +declare global { + interface HTMLElementTagNameMap { + "hui-original-states-dashboard-strategy-editor": HuiOriginalStatesDashboarStrategyEditor; + } +} diff --git a/src/panels/lovelace/editor/hui-element-editor.ts b/src/panels/lovelace/editor/hui-element-editor.ts index 56486d66ec79..916a9e0eeb2b 100644 --- a/src/panels/lovelace/editor/hui-element-editor.ts +++ b/src/panels/lovelace/editor/hui-element-editor.ts @@ -16,8 +16,9 @@ import "../../../components/ha-alert"; import "../../../components/ha-circular-progress"; import "../../../components/ha-code-editor"; import type { HaCodeEditor } from "../../../components/ha-code-editor"; -import type { LovelaceCardConfig } from "../../../data/lovelace/config/card"; -import type { LovelaceConfig } from "../../../data/lovelace/config/types"; +import { LovelaceCardConfig } from "../../../data/lovelace/config/card"; +import { LovelaceStrategyConfig } from "../../../data/lovelace/config/strategy"; +import { LovelaceConfig } from "../../../data/lovelace/config/types"; import type { HomeAssistant } from "../../../types"; import type { LovelaceRowConfig } from "../entity-rows/types"; import { LovelaceHeaderFooterConfig } from "../header-footer/types"; @@ -36,7 +37,8 @@ export interface ConfigChangedEvent { | LovelaceCardConfig | LovelaceRowConfig | LovelaceHeaderFooterConfig - | LovelaceTileFeatureConfig; + | LovelaceTileFeatureConfig + | LovelaceStrategyConfig; error?: string; guiModeAvailable?: boolean; } diff --git a/src/panels/lovelace/hui-root.ts b/src/panels/lovelace/hui-root.ts index eadb8404b334..82b05b7206ea 100644 --- a/src/panels/lovelace/hui-root.ts +++ b/src/panels/lovelace/hui-root.ts @@ -19,12 +19,12 @@ import { import "@polymer/paper-tabs/paper-tab"; import "@polymer/paper-tabs/paper-tabs"; import { - css, CSSResultGroup, - html, LitElement, PropertyValues, TemplateResult, + css, + html, } from "lit"; import { customElement, property, state } from "lit/decorators"; import { classMap } from "lit/directives/class-map"; @@ -64,11 +64,15 @@ import { documentationUrl } from "../../util/documentation-url"; import { swapView } from "./editor/config-util"; import { showEditLovelaceDialog } from "./editor/lovelace-editor/show-edit-lovelace-dialog"; import { showEditViewDialog } from "./editor/view-editor/show-edit-view-dialog"; +import { showDashboardStrategyEditorDialog } from "./strategies/device-registry-detail/show-dialog-dashboard-strategy-editor"; import type { Lovelace } from "./types"; import "./views/hui-view"; import type { HUIView } from "./views/hui-view"; import { LovelaceViewConfig } from "../../data/lovelace/config/view"; -import { LovelaceConfig } from "../../data/lovelace/config/types"; +import { + LovelaceConfig, + isStrategyDashboard, +} from "../../data/lovelace/config/types"; @customElement("hui-root") class HUIRoot extends LitElement { @@ -813,6 +817,13 @@ class HUIRoot extends LitElement { }); return; } + if (isStrategyDashboard(this.lovelace!.rawConfig)) { + showDashboardStrategyEditorDialog(this, { + config: this.lovelace!.rawConfig, + saveConfig: this.lovelace!.saveConfig, + }); + return; + } this.lovelace!.setEditMode(true); } diff --git a/src/panels/lovelace/strategies/device-registry-detail/dialog-dashboard-strategy-editor.ts b/src/panels/lovelace/strategies/device-registry-detail/dialog-dashboard-strategy-editor.ts new file mode 100644 index 000000000000..507e6c340533 --- /dev/null +++ b/src/panels/lovelace/strategies/device-registry-detail/dialog-dashboard-strategy-editor.ts @@ -0,0 +1,129 @@ +import { css, CSSResultGroup, html, LitElement, nothing } from "lit"; +import { customElement, property, query, state } from "lit/decorators"; +import { fireEvent, HASSDomEvent } from "../../../../common/dom/fire_event"; +import "../../../../components/ha-button"; +import { createCloseHeading } from "../../../../components/ha-dialog"; +import { LovelaceStrategyConfig } from "../../../../data/lovelace/config/strategy"; +import { haStyle, haStyleDialog } from "../../../../resources/styles"; +import type { HomeAssistant } from "../../../../types"; +import { showSaveSuccessToast } from "../../../../util/toast-saved-success"; +import "../../editor/dashboard-strategy-editor/hui-dashboard-strategy-element-editor"; +import type { HuiDashboardStrategyElementEditor } from "../../editor/dashboard-strategy-editor/hui-dashboard-strategy-element-editor"; +import { ConfigChangedEvent } from "../../editor/hui-element-editor"; +import { GUIModeChangedEvent } from "../../editor/types"; +import { cleanLegacyStrategyConfig } from "../legacy-strategy"; +import type { DashboardStrategyEditorDialogParams } from "./show-dialog-dashboard-strategy-editor"; + +@customElement("dialog-dashboard-strategy-editor") +class DialogDashboardStrategyEditor extends LitElement { + @property({ attribute: false }) public hass!: HomeAssistant; + + @state() private _params?: DashboardStrategyEditorDialogParams; + + @state() private _strategyConfig?: LovelaceStrategyConfig; + + @state() private _GUImode = true; + + @state() private _guiModeAvailable? = true; + + @query("hui-dashboard-strategy-element-editor") + private _strategyEditorEl?: HuiDashboardStrategyElementEditor; + + public async showDialog( + params: DashboardStrategyEditorDialogParams + ): Promise { + this._params = params; + this._strategyConfig = params.config.strategy; + await this.updateComplete; + } + + public closeDialog(): void { + this._params = undefined; + this._strategyConfig = undefined; + fireEvent(this, "dialog-closed", { dialog: this.localName }); + } + + private _handleConfigChanged(ev: HASSDomEvent) { + ev.stopPropagation(); + this._guiModeAvailable = ev.detail.guiModeAvailable; + this._strategyConfig = ev.detail.config as LovelaceStrategyConfig; + } + + private _handleGUIModeChanged(ev: HASSDomEvent): void { + ev.stopPropagation(); + this._GUImode = ev.detail.guiMode; + this._guiModeAvailable = ev.detail.guiModeAvailable; + } + + private _toggleMode(): void { + this._strategyEditorEl?.toggleMode(); + } + + private _opened() { + this._strategyEditorEl?.focusYamlEditor(); + } + + private async _save(): Promise { + await this._params!.saveConfig({ + ...this._params!.config, + strategy: this._strategyConfig!, + }); + showSaveSuccessToast(this, this.hass); + this.closeDialog(); + } + + protected render() { + if (!this._params || !this._strategyConfig) { + return nothing; + } + + const config = cleanLegacyStrategyConfig(this._strategyConfig); + + return html` + + + ${this._strategyConfig !== undefined + ? html` + + ${this.hass!.localize( + !this._strategyEditorEl || this._GUImode + ? "ui.panel.lovelace.editor.edit_card.show_code_editor" + : "ui.panel.lovelace.editor.edit_card.show_visual_editor" + )} + + + ${this.hass!.localize("ui.common.save")} + + ` + : nothing} + + `; + } + + static get styles(): CSSResultGroup { + return [haStyle, haStyleDialog, css``]; + } +} + +declare global { + interface HTMLElementTagNameMap { + "dialog-dashboard-strategy-editor": DialogDashboardStrategyEditor; + } +} diff --git a/src/panels/lovelace/strategies/device-registry-detail/show-dialog-dashboard-strategy-editor.ts b/src/panels/lovelace/strategies/device-registry-detail/show-dialog-dashboard-strategy-editor.ts new file mode 100644 index 000000000000..822952cd0dd1 --- /dev/null +++ b/src/panels/lovelace/strategies/device-registry-detail/show-dialog-dashboard-strategy-editor.ts @@ -0,0 +1,21 @@ +import { fireEvent } from "../../../../common/dom/fire_event"; +import { LovelaceDashboardStrategyConfig } from "../../../../data/lovelace/config/types"; + +export interface DashboardStrategyEditorDialogParams { + config: LovelaceDashboardStrategyConfig; + saveConfig: (config: LovelaceDashboardStrategyConfig) => void; +} + +export const loadDashboardStrategyEditorDialog = () => + import("./dialog-dashboard-strategy-editor"); + +export const showDashboardStrategyEditorDialog = ( + element: HTMLElement, + params: DashboardStrategyEditorDialogParams +): void => { + fireEvent(element, "show-dialog", { + dialogTag: "dialog-dashboard-strategy-editor", + dialogImport: loadDashboardStrategyEditorDialog, + dialogParams: params, + }); +}; diff --git a/src/panels/lovelace/strategies/get-strategy.ts b/src/panels/lovelace/strategies/get-strategy.ts index cf507c78ac94..ee62115275df 100644 --- a/src/panels/lovelace/strategies/get-strategy.ts +++ b/src/panels/lovelace/strategies/get-strategy.ts @@ -9,7 +9,7 @@ import { isStrategyView, } from "../../../data/lovelace/config/view"; import { AsyncReturnType, HomeAssistant } from "../../../types"; -import { isLegacyStrategy } from "./legacy-strategy"; +import { cleanLegacyStrategyConfig, isLegacyStrategy } from "./legacy-strategy"; import { LovelaceDashboardStrategy, LovelaceStrategy, @@ -40,7 +40,7 @@ type StrategyConfig = AsyncReturnType< Strategies[T]["generate"] >; -const getLovelaceStrategy = async ( +export const getLovelaceStrategy = async ( configType: T, strategyType: string ): Promise => { @@ -109,12 +109,7 @@ const generateStrategy = async ( } } - const config = { - ...strategyConfig, - ...strategyConfig.options, - }; - - delete config.options; + const config = cleanLegacyStrategyConfig(strategyConfig); return await strategy.generate(config, hass); } catch (err: any) { diff --git a/src/panels/lovelace/strategies/legacy-strategy.ts b/src/panels/lovelace/strategies/legacy-strategy.ts index 7ce729f0cd8b..98c786ad053f 100644 --- a/src/panels/lovelace/strategies/legacy-strategy.ts +++ b/src/panels/lovelace/strategies/legacy-strategy.ts @@ -1,3 +1,4 @@ +import { LovelaceStrategyConfig } from "../../../data/lovelace/config/strategy"; import { LovelaceConfig, LovelaceRawConfig, @@ -27,3 +28,16 @@ export interface LovelaceViewStrategy { hass: HomeAssistant; }): Promise; } + +export const cleanLegacyStrategyConfig = (config: LovelaceStrategyConfig) => { + if (!(Object.keys(config).length === 2 && "options" in config)) { + return config; + } + const cleanedConfig = { + ...config, + ...config.options, + }; + + delete cleanedConfig.options; + return cleanedConfig; +}; diff --git a/src/panels/lovelace/strategies/original-states-dashboard-strategy.ts b/src/panels/lovelace/strategies/original-states-dashboard-strategy.ts index c8717140b5aa..86f010d9a49e 100644 --- a/src/panels/lovelace/strategies/original-states-dashboard-strategy.ts +++ b/src/panels/lovelace/strategies/original-states-dashboard-strategy.ts @@ -1,15 +1,17 @@ import { ReactiveElement } from "lit"; import { customElement } from "lit/decorators"; +import { LovelaceConfig } from "../../../data/lovelace/config/types"; import { HomeAssistant } from "../../../types"; import { OriginalStatesViewStrategyConfig } from "./original-states-view-strategy"; -import { LovelaceConfig } from "../../../data/lovelace/config/types"; +import { LovelaceStrategyEditor } from "./types"; -type OriginalStatesStrategyConfig = OriginalStatesViewStrategyConfig; +export type OriginalStatesDashboardStrategyConfig = + OriginalStatesViewStrategyConfig; @customElement("original-states-dashboard-strategy") export class OriginalStatesDashboardStrategy extends ReactiveElement { static async generate( - config: OriginalStatesStrategyConfig, + config: OriginalStatesDashboardStrategyConfig, hass: HomeAssistant ): Promise { return { @@ -21,4 +23,13 @@ export class OriginalStatesDashboardStrategy extends ReactiveElement { ], }; } + + public static async getConfigElement(): Promise { + await import( + "../editor/dashboard-strategy-editor/hui-original-states-dashboard-strategy-editor" + ); + return document.createElement( + "hui-original-states-dashboard-strategy-editor" + ); + } } diff --git a/src/panels/lovelace/strategies/types.ts b/src/panels/lovelace/strategies/types.ts index ea4946a8006e..da2ab8ee3c00 100644 --- a/src/panels/lovelace/strategies/types.ts +++ b/src/panels/lovelace/strategies/types.ts @@ -2,9 +2,11 @@ import { LovelaceConfig } from "../../../data/lovelace/config/types"; import { LovelaceStrategyConfig } from "../../../data/lovelace/config/strategy"; import { LovelaceViewConfig } from "../../../data/lovelace/config/view"; import { HomeAssistant } from "../../../types"; +import { LovelaceGenericElementEditor } from "../types"; export type LovelaceStrategy = { generate(config: LovelaceStrategyConfig, hass: HomeAssistant): Promise; + getConfigElement?: () => LovelaceStrategyEditor; }; export interface LovelaceDashboardStrategy @@ -12,3 +14,7 @@ export interface LovelaceDashboardStrategy export interface LovelaceViewStrategy extends LovelaceStrategy {} + +export interface LovelaceStrategyEditor extends LovelaceGenericElementEditor { + setConfig(config: LovelaceStrategyConfig): void; +} From 53d1d3bb4f2fc59d40dba5a8ef9592b0621a0abb Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Wed, 15 Nov 2023 15:28:28 +0100 Subject: [PATCH 03/10] Add editor and take control --- ...iginal-states-dashboard-strategy-editor.ts | 37 ++++-- src/panels/lovelace/hui-root.ts | 8 ++ .../dialog-dashboard-strategy-editor.ts | 115 +++++++++++++----- .../show-dialog-dashboard-strategy-editor.ts | 1 + 4 files changed, 121 insertions(+), 40 deletions(-) diff --git a/src/panels/lovelace/editor/dashboard-strategy-editor/hui-original-states-dashboard-strategy-editor.ts b/src/panels/lovelace/editor/dashboard-strategy-editor/hui-original-states-dashboard-strategy-editor.ts index d411ce5af9c2..8618e9d141c5 100644 --- a/src/panels/lovelace/editor/dashboard-strategy-editor/hui-original-states-dashboard-strategy-editor.ts +++ b/src/panels/lovelace/editor/dashboard-strategy-editor/hui-original-states-dashboard-strategy-editor.ts @@ -12,11 +12,32 @@ import { LovelaceStrategyEditor } from "../../strategies/types"; const SCHEMA = [ { - name: "no_area_group", + name: "hidden_areas", selector: { - boolean: {}, + area: { + multiple: true, + entity: {}, + }, }, }, + { + name: "", + type: "grid", + schema: [ + { + name: "hide_entities_without_area", + selector: { + boolean: {}, + }, + }, + { + name: "hide_energy", + selector: { + boolean: {}, + }, + }, + ], + }, ] as const satisfies readonly HaFormSchema[]; @customElement("hui-original-states-dashboard-strategy-editor") @@ -58,12 +79,14 @@ export class HuiOriginalStatesDashboarStrategyEditor private _computeLabelCallback = (schema: SchemaUnion) => { switch (schema.name) { - case "no_area_group": - return "Do not group by area"; + case "hidden_areas": + return "Hiddens areas"; + case "hide_energy": + return "Hide energy overview"; + case "hide_entities_without_area": + return "Hide entities without area"; default: - return this.hass!.localize( - `ui.panel.lovelace.editor.card.generic.${schema.name}` - ); + return ""; } }; } diff --git a/src/panels/lovelace/hui-root.ts b/src/panels/lovelace/hui-root.ts index 82b05b7206ea..be41cba2066b 100644 --- a/src/panels/lovelace/hui-root.ts +++ b/src/panels/lovelace/hui-root.ts @@ -73,6 +73,7 @@ import { LovelaceConfig, isStrategyDashboard, } from "../../data/lovelace/config/types"; +import { showSaveDialog } from "./editor/show-save-config-dialog"; @customElement("hui-root") class HUIRoot extends LitElement { @@ -821,6 +822,13 @@ class HUIRoot extends LitElement { showDashboardStrategyEditorDialog(this, { config: this.lovelace!.rawConfig, saveConfig: this.lovelace!.saveConfig, + takeControl: () => { + showSaveDialog(this, { + lovelace: this.lovelace!, + mode: "storage", + narrow: this.narrow!, + }); + }, }); return; } diff --git a/src/panels/lovelace/strategies/device-registry-detail/dialog-dashboard-strategy-editor.ts b/src/panels/lovelace/strategies/device-registry-detail/dialog-dashboard-strategy-editor.ts index 507e6c340533..8550da9b3c4b 100644 --- a/src/panels/lovelace/strategies/device-registry-detail/dialog-dashboard-strategy-editor.ts +++ b/src/panels/lovelace/strategies/device-registry-detail/dialog-dashboard-strategy-editor.ts @@ -1,10 +1,15 @@ -import { css, CSSResultGroup, html, LitElement, nothing } from "lit"; +import { mdiAccountHardHat, mdiClose, mdiDotsVertical } from "@mdi/js"; +import { CSSResultGroup, LitElement, css, html, nothing } from "lit"; import { customElement, property, query, state } from "lit/decorators"; -import { fireEvent, HASSDomEvent } from "../../../../common/dom/fire_event"; +import { HASSDomEvent, fireEvent } from "../../../../common/dom/fire_event"; +import { stopPropagation } from "../../../../common/dom/stop_propagation"; import "../../../../components/ha-button"; -import { createCloseHeading } from "../../../../components/ha-dialog"; +import "../../../../components/ha-button-menu"; +import "../../../../components/ha-dialog"; +import "../../../../components/ha-dialog-header"; +import "../../../../components/ha-icon-button"; import { LovelaceStrategyConfig } from "../../../../data/lovelace/config/strategy"; -import { haStyle, haStyleDialog } from "../../../../resources/styles"; +import { haStyleDialog } from "../../../../resources/styles"; import type { HomeAssistant } from "../../../../types"; import { showSaveSuccessToast } from "../../../../util/toast-saved-success"; import "../../editor/dashboard-strategy-editor/hui-dashboard-strategy-element-editor"; @@ -79,46 +84,90 @@ class DialogDashboardStrategyEditor extends LitElement { const config = cleanLegacyStrategyConfig(this._strategyConfig); + const title = "Edit dashboard"; + return html` - - ${this._strategyConfig !== undefined - ? html` - - ${this.hass!.localize( - !this._strategyEditorEl || this._GUImode - ? "ui.panel.lovelace.editor.edit_card.show_code_editor" - : "ui.panel.lovelace.editor.edit_card.show_visual_editor" - )} - - - ${this.hass!.localize("ui.common.save")} - - ` - : nothing} + + + ${title} + + + + Take control + + + + +
+ +
+ + + ${this.hass!.localize( + !this._strategyEditorEl || this._GUImode + ? "ui.panel.lovelace.editor.edit_card.show_code_editor" + : "ui.panel.lovelace.editor.edit_card.show_visual_editor" + )} + + + ${this.hass!.localize("ui.common.save")} +
`; } + private _takeControl() { + this._params!.takeControl(); + this.closeDialog(); + } + static get styles(): CSSResultGroup { - return [haStyle, haStyleDialog, css``]; + return [ + haStyleDialog, + css` + ha-dialog { + --mdc-dialog-max-width: 800px; + } + `, + ]; } } diff --git a/src/panels/lovelace/strategies/device-registry-detail/show-dialog-dashboard-strategy-editor.ts b/src/panels/lovelace/strategies/device-registry-detail/show-dialog-dashboard-strategy-editor.ts index 822952cd0dd1..c2dbdd020c37 100644 --- a/src/panels/lovelace/strategies/device-registry-detail/show-dialog-dashboard-strategy-editor.ts +++ b/src/panels/lovelace/strategies/device-registry-detail/show-dialog-dashboard-strategy-editor.ts @@ -4,6 +4,7 @@ import { LovelaceDashboardStrategyConfig } from "../../../../data/lovelace/confi export interface DashboardStrategyEditorDialogParams { config: LovelaceDashboardStrategyConfig; saveConfig: (config: LovelaceDashboardStrategyConfig) => void; + takeControl: () => void; } export const loadDashboardStrategyEditorDialog = () => From 99f4e09f7e29778395c07bf19f7fd1718fac14aa Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Wed, 15 Nov 2023 15:54:40 +0100 Subject: [PATCH 04/10] Add raw editor and translations --- src/panels/lovelace/hui-root.ts | 3 ++ .../dialog-dashboard-strategy-editor.ts | 36 +++++++++++++++---- .../show-dialog-dashboard-strategy-editor.ts | 1 + src/translations/en.json | 7 ++++ 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/panels/lovelace/hui-root.ts b/src/panels/lovelace/hui-root.ts index be41cba2066b..12330f6e3d7a 100644 --- a/src/panels/lovelace/hui-root.ts +++ b/src/panels/lovelace/hui-root.ts @@ -829,6 +829,9 @@ class HUIRoot extends LitElement { narrow: this.narrow!, }); }, + showRawConfigEditor: () => { + this.lovelace!.enableFullEditMode(); + }, }); return; } diff --git a/src/panels/lovelace/strategies/device-registry-detail/dialog-dashboard-strategy-editor.ts b/src/panels/lovelace/strategies/device-registry-detail/dialog-dashboard-strategy-editor.ts index 8550da9b3c4b..e114547246f3 100644 --- a/src/panels/lovelace/strategies/device-registry-detail/dialog-dashboard-strategy-editor.ts +++ b/src/panels/lovelace/strategies/device-registry-detail/dialog-dashboard-strategy-editor.ts @@ -1,4 +1,9 @@ -import { mdiAccountHardHat, mdiClose, mdiDotsVertical } from "@mdi/js"; +import { + mdiAccountHardHat, + mdiClose, + mdiCodeBraces, + mdiDotsVertical, +} from "@mdi/js"; import { CSSResultGroup, LitElement, css, html, nothing } from "lit"; import { customElement, property, query, state } from "lit/decorators"; import { HASSDomEvent, fireEvent } from "../../../../common/dom/fire_event"; @@ -84,7 +89,9 @@ class DialogDashboardStrategyEditor extends LitElement { const config = cleanLegacyStrategyConfig(this._strategyConfig); - const title = "Edit dashboard"; + const title = this.hass.localize( + "ui.panel.lovelace.editor.strategy-editor.header" + ); return html` + + ${this.hass.localize( + "ui.panel.lovelace.editor.strategy-editor.raw_configuration_editor" + )} + + - Take control + ${this.hass.localize( + "ui.panel.lovelace.editor.strategy-editor.take_control" + )} ${this.hass!.localize( !this._strategyEditorEl || this._GUImode - ? "ui.panel.lovelace.editor.edit_card.show_code_editor" - : "ui.panel.lovelace.editor.edit_card.show_visual_editor" + ? "ui.panel.lovelace.editor.strategy-editor.show_code_editor" + : "ui.panel.lovelace.editor.strategy-editor.show_visual_editor" )} @@ -159,12 +177,18 @@ class DialogDashboardStrategyEditor extends LitElement { this.closeDialog(); } + private _showRawConfigEditor() { + this._params!.showRawConfigEditor(); + this.closeDialog(); + } + static get styles(): CSSResultGroup { return [ haStyleDialog, css` ha-dialog { --mdc-dialog-max-width: 800px; + --dialog-content-padding: 0 24px; } `, ]; diff --git a/src/panels/lovelace/strategies/device-registry-detail/show-dialog-dashboard-strategy-editor.ts b/src/panels/lovelace/strategies/device-registry-detail/show-dialog-dashboard-strategy-editor.ts index c2dbdd020c37..9ad34cc51ded 100644 --- a/src/panels/lovelace/strategies/device-registry-detail/show-dialog-dashboard-strategy-editor.ts +++ b/src/panels/lovelace/strategies/device-registry-detail/show-dialog-dashboard-strategy-editor.ts @@ -5,6 +5,7 @@ export interface DashboardStrategyEditorDialogParams { config: LovelaceDashboardStrategyConfig; saveConfig: (config: LovelaceDashboardStrategyConfig) => void; takeControl: () => void; + showRawConfigEditor: () => void; } export const loadDashboardStrategyEditorDialog = () => diff --git a/src/translations/en.json b/src/translations/en.json index aded614d0273..2fb4cce35b8c 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -4870,6 +4870,13 @@ } } }, + "strategy-editor": { + "header": "Edit dashboard", + "take_control": "Take control", + "raw_configuration_editor": "[%key:ui::panel::lovelace::editor::menu::raw_editor%]", + "show_code_editor": "[%key:ui::panel::lovelace::editor::edit_card::show_visual_editor%]", + "show_visual_editor": "[%key:ui::panel::lovelace::editor::edit_card::show_visual_editor%]" + }, "card": { "alarm-panel": { "name": "Alarm panel", From 9395d4b6a5dbc4e71539540abbd10f26436c1fc0 Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Wed, 15 Nov 2023 16:26:36 +0100 Subject: [PATCH 05/10] Don't show editor for legacy strategy config --- src/panels/lovelace/hui-root.ts | 6 +++++- src/panels/lovelace/strategies/legacy-strategy.ts | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/panels/lovelace/hui-root.ts b/src/panels/lovelace/hui-root.ts index 12330f6e3d7a..7267f95e0a44 100644 --- a/src/panels/lovelace/hui-root.ts +++ b/src/panels/lovelace/hui-root.ts @@ -74,6 +74,7 @@ import { isStrategyDashboard, } from "../../data/lovelace/config/types"; import { showSaveDialog } from "./editor/show-save-config-dialog"; +import { isLegacyStrategyConfig } from "./strategies/legacy-strategy"; @customElement("hui-root") class HUIRoot extends LitElement { @@ -818,7 +819,10 @@ class HUIRoot extends LitElement { }); return; } - if (isStrategyDashboard(this.lovelace!.rawConfig)) { + if ( + isStrategyDashboard(this.lovelace!.rawConfig) && + !isLegacyStrategyConfig(this.lovelace!.rawConfig.strategy) + ) { showDashboardStrategyEditorDialog(this, { config: this.lovelace!.rawConfig, saveConfig: this.lovelace!.saveConfig, diff --git a/src/panels/lovelace/strategies/legacy-strategy.ts b/src/panels/lovelace/strategies/legacy-strategy.ts index 98c786ad053f..335c33072a42 100644 --- a/src/panels/lovelace/strategies/legacy-strategy.ts +++ b/src/panels/lovelace/strategies/legacy-strategy.ts @@ -29,8 +29,14 @@ export interface LovelaceViewStrategy { }): Promise; } +// We assume that if a strategy config has only "type" and "options" parameters, it's a legacy strategy config +export const isLegacyStrategyConfig = (config: LovelaceStrategyConfig) => + Object.keys(config).length === 2 && + "options" in config && + typeof config.options === "object"; + export const cleanLegacyStrategyConfig = (config: LovelaceStrategyConfig) => { - if (!(Object.keys(config).length === 2 && "options" in config)) { + if (!isLegacyStrategyConfig(config)) { return config; } const cleanedConfig = { From 182eb1aaa459486cde76b7e47ccd2785c473dfe5 Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Thu, 16 Nov 2023 13:51:39 +0100 Subject: [PATCH 06/10] Update en.json Co-authored-by: Simon Lamon <32477463+silamon@users.noreply.github.com> --- src/translations/en.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/translations/en.json b/src/translations/en.json index 2fb4cce35b8c..f5715cde36a7 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -4874,7 +4874,7 @@ "header": "Edit dashboard", "take_control": "Take control", "raw_configuration_editor": "[%key:ui::panel::lovelace::editor::menu::raw_editor%]", - "show_code_editor": "[%key:ui::panel::lovelace::editor::edit_card::show_visual_editor%]", + "show_code_editor": "[%key:ui::panel::lovelace::editor::edit_card::show_code_editor%]", "show_visual_editor": "[%key:ui::panel::lovelace::editor::edit_card::show_visual_editor%]" }, "card": { From aff58673db4f20ee30f1208bb641124ef1b945e7 Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Wed, 22 Nov 2023 10:27:20 +0100 Subject: [PATCH 07/10] Convert hidden areas config to area filter --- src/components/ha-areas-picker.ts | 1 + .../common/generate-lovelace-config.ts | 8 ++-- ...iginal-states-dashboard-strategy-editor.ts | 39 +++++++++++++++++-- .../original-states-view-strategy.ts | 6 ++- 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/components/ha-areas-picker.ts b/src/components/ha-areas-picker.ts index f3fb1e48cb03..eff9622a0a01 100644 --- a/src/components/ha-areas-picker.ts +++ b/src/components/ha-areas-picker.ts @@ -102,6 +102,7 @@ export class HaAreasPicker extends SubscribeMixin(LitElement) { .placeholder=${this.placeholder} .required=${this.required && !currentAreas.length} @value-changed=${this._addArea} + .excludeAreas=${currentAreas} > `; diff --git a/src/panels/lovelace/common/generate-lovelace-config.ts b/src/panels/lovelace/common/generate-lovelace-config.ts index 27aa1f885017..5f1d95fec879 100644 --- a/src/panels/lovelace/common/generate-lovelace-config.ts +++ b/src/panels/lovelace/common/generate-lovelace-config.ts @@ -447,7 +447,9 @@ export const generateDefaultViewConfig = ( entities: HassEntities, localize: LocalizeFunc, energyPrefs?: EnergyPreferences, - hiddenAreas?: string[], + areasFilter?: { + hidden?: string[]; + }, hideEntitiesWithoutAreas?: boolean, hideEnergy?: boolean ): LovelaceViewConfig => { @@ -472,8 +474,8 @@ export const generateDefaultViewConfig = ( states ); - if (hiddenAreas) { - for (const area of hiddenAreas) { + if (areasFilter?.hidden) { + for (const area of areasFilter.hidden) { splittedByAreaDevice.areasWithEntities[area] = []; } } diff --git a/src/panels/lovelace/editor/dashboard-strategy-editor/hui-original-states-dashboard-strategy-editor.ts b/src/panels/lovelace/editor/dashboard-strategy-editor/hui-original-states-dashboard-strategy-editor.ts index 8618e9d141c5..5666a503cefd 100644 --- a/src/panels/lovelace/editor/dashboard-strategy-editor/hui-original-states-dashboard-strategy-editor.ts +++ b/src/panels/lovelace/editor/dashboard-strategy-editor/hui-original-states-dashboard-strategy-editor.ts @@ -1,5 +1,6 @@ import { html, LitElement, nothing } from "lit"; import { customElement, property, state } from "lit/decorators"; +import memoizeOne from "memoize-one"; import { fireEvent } from "../../../../common/dom/fire_event"; import "../../../../components/ha-form/ha-form"; import type { @@ -16,7 +17,6 @@ const SCHEMA = [ selector: { area: { multiple: true, - entity: {}, }, }, }, @@ -40,6 +40,12 @@ const SCHEMA = [ }, ] as const satisfies readonly HaFormSchema[]; +type FormData = { + hidden_areas: string[]; + hide_energy?: boolean; + hide_entities_without_area?: boolean; +}; + @customElement("hui-original-states-dashboard-strategy-editor") export class HuiOriginalStatesDashboarStrategyEditor extends LitElement @@ -54,12 +60,36 @@ export class HuiOriginalStatesDashboarStrategyEditor this._config = config; } + private _configToFormData = memoizeOne( + (config: OriginalStatesDashboardStrategyConfig): FormData => { + const { areas_filter, ...rest } = config; + return { + ...rest, + hidden_areas: areas_filter?.hidden || [], + }; + } + ); + + private _formDataToConfig = memoizeOne( + (data: FormData): OriginalStatesDashboardStrategyConfig => { + const { hidden_areas, ...rest } = data; + const areaFilter = { + hidden: hidden_areas, + }; + return { + type: "original-states", + ...rest, + areas_filter: areaFilter, + }; + } + ); + protected render() { if (!this.hass || !this._config) { return nothing; } - const data = this._config; + const data = this._configToFormData(this._config); return html` ) => { switch (schema.name) { case "hidden_areas": - return "Hiddens areas"; + return "Hidden areas"; case "hide_energy": return "Hide energy overview"; case "hide_entities_without_area": diff --git a/src/panels/lovelace/strategies/original-states-view-strategy.ts b/src/panels/lovelace/strategies/original-states-view-strategy.ts index fe3c6611880b..6f028036f23c 100644 --- a/src/panels/lovelace/strategies/original-states-view-strategy.ts +++ b/src/panels/lovelace/strategies/original-states-view-strategy.ts @@ -9,7 +9,9 @@ import { generateDefaultViewConfig } from "../common/generate-lovelace-config"; export type OriginalStatesViewStrategyConfig = { type: "original-states"; - hidden_areas?: string[]; + areas_filter?: { + hidden?: string[]; + }; hide_entities_without_area?: boolean; hide_energy?: boolean; }; @@ -49,7 +51,7 @@ export class OriginalStatesViewStrategy extends ReactiveElement { hass.states, localize, energyPrefs, - config.hidden_areas, + config.areas_filter, config.hide_entities_without_area, config.hide_energy ); From cd8520b6e8d2e7f4253a4d06cd31ac6a3eab2e8f Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Wed, 22 Nov 2023 11:24:59 +0100 Subject: [PATCH 08/10] Fix clear area picker --- src/components/ha-area-picker.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/components/ha-area-picker.ts b/src/components/ha-area-picker.ts index 5d56c6908203..d4cb739adccc 100644 --- a/src/components/ha-area-picker.ts +++ b/src/components/ha-area-picker.ts @@ -328,7 +328,7 @@ export class HaAreaPicker extends LitElement { item-value-path="area_id" item-id-path="area_id" item-label-path="name" - .value=${this.value} + .value=${this._value} .disabled=${this.disabled} .required=${this.required} .label=${this.label === undefined && this.hass @@ -347,18 +347,19 @@ export class HaAreaPicker extends LitElement { } private _filterChanged(ev: CustomEvent): void { - const filter = ev.detail.value; - if (!filter) { + const target = ev.target as HaComboBox; + const filterString = ev.detail.value; + if (!filterString) { this.comboBox.filteredItems = this.comboBox.items; return; } const filteredItems = fuzzyFilterSort( - filter, - this.comboBox?.items || [] + filterString, + target.items || [] ); if (!this.noAdd && filteredItems?.length === 0) { - this._suggestion = filter; + this._suggestion = filterString; this.comboBox.filteredItems = [ { area_id: "add_new_suggestion", From 173e7b14d600a2534c3f97df3c8d1ff4149d4fc7 Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Wed, 22 Nov 2023 11:25:53 +0100 Subject: [PATCH 09/10] Rename area field --- .../lovelace/common/generate-lovelace-config.ts | 6 +++--- ...i-original-states-dashboard-strategy-editor.ts | 15 +++++++++------ .../strategies/original-states-view-strategy.ts | 4 ++-- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/panels/lovelace/common/generate-lovelace-config.ts b/src/panels/lovelace/common/generate-lovelace-config.ts index 5f1d95fec879..300a713f0bf4 100644 --- a/src/panels/lovelace/common/generate-lovelace-config.ts +++ b/src/panels/lovelace/common/generate-lovelace-config.ts @@ -447,7 +447,7 @@ export const generateDefaultViewConfig = ( entities: HassEntities, localize: LocalizeFunc, energyPrefs?: EnergyPreferences, - areasFilter?: { + areasPrefs?: { hidden?: string[]; }, hideEntitiesWithoutAreas?: boolean, @@ -474,8 +474,8 @@ export const generateDefaultViewConfig = ( states ); - if (areasFilter?.hidden) { - for (const area of areasFilter.hidden) { + if (areasPrefs?.hidden) { + for (const area of areasPrefs.hidden) { splittedByAreaDevice.areasWithEntities[area] = []; } } diff --git a/src/panels/lovelace/editor/dashboard-strategy-editor/hui-original-states-dashboard-strategy-editor.ts b/src/panels/lovelace/editor/dashboard-strategy-editor/hui-original-states-dashboard-strategy-editor.ts index 5666a503cefd..658e224f8436 100644 --- a/src/panels/lovelace/editor/dashboard-strategy-editor/hui-original-states-dashboard-strategy-editor.ts +++ b/src/panels/lovelace/editor/dashboard-strategy-editor/hui-original-states-dashboard-strategy-editor.ts @@ -62,10 +62,10 @@ export class HuiOriginalStatesDashboarStrategyEditor private _configToFormData = memoizeOne( (config: OriginalStatesDashboardStrategyConfig): FormData => { - const { areas_filter, ...rest } = config; + const { areas, ...rest } = config; return { ...rest, - hidden_areas: areas_filter?.hidden || [], + hidden_areas: areas?.hidden || [], }; } ); @@ -73,13 +73,16 @@ export class HuiOriginalStatesDashboarStrategyEditor private _formDataToConfig = memoizeOne( (data: FormData): OriginalStatesDashboardStrategyConfig => { const { hidden_areas, ...rest } = data; - const areaFilter = { - hidden: hidden_areas, - }; + const areas = + hidden_areas.length > 0 + ? { + hidden: hidden_areas, + } + : undefined; return { type: "original-states", ...rest, - areas_filter: areaFilter, + areas, }; } ); diff --git a/src/panels/lovelace/strategies/original-states-view-strategy.ts b/src/panels/lovelace/strategies/original-states-view-strategy.ts index 6f028036f23c..86f3017315d1 100644 --- a/src/panels/lovelace/strategies/original-states-view-strategy.ts +++ b/src/panels/lovelace/strategies/original-states-view-strategy.ts @@ -9,7 +9,7 @@ import { generateDefaultViewConfig } from "../common/generate-lovelace-config"; export type OriginalStatesViewStrategyConfig = { type: "original-states"; - areas_filter?: { + areas?: { hidden?: string[]; }; hide_entities_without_area?: boolean; @@ -51,7 +51,7 @@ export class OriginalStatesViewStrategy extends ReactiveElement { hass.states, localize, energyPrefs, - config.areas_filter, + config.areas, config.hide_entities_without_area, config.hide_energy ); From 1cc17168eb1b5464981d7472d2f19aebec0aec6d Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Wed, 22 Nov 2023 12:01:13 +0100 Subject: [PATCH 10/10] Add translations --- .../hui-original-states-dashboard-strategy-editor.ts | 6 +++--- src/translations/en.json | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/panels/lovelace/editor/dashboard-strategy-editor/hui-original-states-dashboard-strategy-editor.ts b/src/panels/lovelace/editor/dashboard-strategy-editor/hui-original-states-dashboard-strategy-editor.ts index 658e224f8436..77e5c58034e2 100644 --- a/src/panels/lovelace/editor/dashboard-strategy-editor/hui-original-states-dashboard-strategy-editor.ts +++ b/src/panels/lovelace/editor/dashboard-strategy-editor/hui-original-states-dashboard-strategy-editor.ts @@ -114,11 +114,11 @@ export class HuiOriginalStatesDashboarStrategyEditor private _computeLabelCallback = (schema: SchemaUnion) => { switch (schema.name) { case "hidden_areas": - return "Hidden areas"; case "hide_energy": - return "Hide energy overview"; case "hide_entities_without_area": - return "Hide entities without area"; + return this.hass?.localize( + `ui.panel.lovelace.editor.strategy.original-states.${schema.name}` + ); default: return ""; } diff --git a/src/translations/en.json b/src/translations/en.json index f5715cde36a7..04df45576e0f 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -5271,6 +5271,13 @@ "twice_daily": "Twice daily" } }, + "strategy": { + "original-states": { + "hidden_areas": "Hidden Areas", + "hide_entities_without_area": "Hide entities without area", + "hide_energy": "Hide energy" + } + }, "view": { "panel_mode": { "warning_multiple_cards": "This view contains more than one card, but a panel view can only show 1 card."