From 67f3d31a4be84d3371f76620589c1cff0508ec74 Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Tue, 13 May 2025 07:54:31 +0200 Subject: [PATCH] Fix domain not translated in entity picker and quick bar (#25444) * Fix domain not translated in entity picker * Remove unused param --- src/components/entity/ha-entity-picker.ts | 15 +++++++++++- src/dialogs/quick-bar/ha-quick-bar.ts | 30 +++++++++++------------ 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/components/entity/ha-entity-picker.ts b/src/components/entity/ha-entity-picker.ts index 515a5a58b4..40e448bae2 100644 --- a/src/components/entity/ha-entity-picker.ts +++ b/src/components/entity/ha-entity-picker.ts @@ -1,6 +1,13 @@ import { mdiClose, mdiMenuDown, mdiShape } from "@mdi/js"; import type { ComboBoxLightOpenedChangedEvent } from "@vaadin/combo-box/vaadin-combo-box-light"; -import { css, html, LitElement, nothing, type CSSResultGroup } from "lit"; +import { + css, + html, + LitElement, + nothing, + type CSSResultGroup, + type PropertyValues, +} from "lit"; import { customElement, property, query, state } from "lit/decorators"; import { fireEvent } from "../../common/dom/fire_event"; import { stopPropagation } from "../../common/dom/stop_propagation"; @@ -106,6 +113,12 @@ export class HaEntityPicker extends LitElement { @state() private _opened = false; + protected firstUpdated(changedProperties: PropertyValues): void { + super.firstUpdated(changedProperties); + // Load title translations so it is available when the combo-box opens + this.hass.loadBackendTranslation("title"); + } + private _renderContent() { const entityId = this.value || ""; diff --git a/src/dialogs/quick-bar/ha-quick-bar.ts b/src/dialogs/quick-bar/ha-quick-bar.ts index 21b1215e06..f27ff5b428 100644 --- a/src/dialogs/quick-bar/ha-quick-bar.ts +++ b/src/dialogs/quick-bar/ha-quick-bar.ts @@ -9,50 +9,50 @@ import { mdiReload, mdiServerNetwork, } from "@mdi/js"; +import Fuse from "fuse.js"; import type { TemplateResult } from "lit"; import { css, html, LitElement, nothing } from "lit"; import { customElement, property, query, state } from "lit/decorators"; import { ifDefined } from "lit/directives/if-defined"; import { styleMap } from "lit/directives/style-map"; import memoizeOne from "memoize-one"; -import Fuse from "fuse.js"; import { canShowPage } from "../../common/config/can_show_page"; import { componentsWithService } from "../../common/config/components_with_service"; import { isComponentLoaded } from "../../common/config/is_component_loaded"; import { fireEvent } from "../../common/dom/fire_event"; +import { computeAreaName } from "../../common/entity/compute_area_name"; import { computeDeviceName, computeDeviceNameDisplay, } from "../../common/entity/compute_device_name"; +import { computeDomain } from "../../common/entity/compute_domain"; +import { computeEntityName } from "../../common/entity/compute_entity_name"; +import { computeStateName } from "../../common/entity/compute_state_name"; +import { getEntityContext } from "../../common/entity/context/get_entity_context"; import { navigate } from "../../common/navigate"; import { caseInsensitiveStringCompare } from "../../common/string/compare"; import type { ScorableTextItem } from "../../common/string/filter/sequence-matching"; +import { computeRTL } from "../../common/util/compute_rtl"; import { debounce } from "../../common/util/debounce"; import "../../components/ha-icon-button"; import "../../components/ha-label"; import "../../components/ha-list"; +import "../../components/ha-md-list-item"; import "../../components/ha-spinner"; import "../../components/ha-textfield"; import "../../components/ha-tip"; -import "../../components/ha-md-list-item"; import { fetchHassioAddonsInfo } from "../../data/hassio/addon"; import { domainToName } from "../../data/integration"; import { getPanelNameTranslationKey } from "../../data/panel"; import type { PageNavigation } from "../../layouts/hass-tabs-subpage"; import { configSections } from "../../panels/config/ha-panel-config"; +import { HaFuse } from "../../resources/fuse"; import { haStyleDialog, haStyleScrollbar } from "../../resources/styles"; import { loadVirtualizer } from "../../resources/virtualizer"; import type { HomeAssistant } from "../../types"; import { showConfirmationDialog } from "../generic/show-dialog-box"; import { showShortcutsDialog } from "../shortcuts/show-shortcuts-dialog"; import { QuickBarMode, type QuickBarParams } from "./show-dialog-quick-bar"; -import { getEntityContext } from "../../common/entity/context/get_entity_context"; -import { computeEntityName } from "../../common/entity/compute_entity_name"; -import { computeAreaName } from "../../common/entity/compute_area_name"; -import { computeRTL } from "../../common/util/compute_rtl"; -import { computeDomain } from "../../common/entity/compute_domain"; -import { computeStateName } from "../../common/entity/compute_state_name"; -import { HaFuse } from "../../resources/fuse"; interface QuickBarItem extends ScorableTextItem { primaryText: string; @@ -152,11 +152,6 @@ export class QuickBar extends LitElement { } } - protected firstUpdated(changedProps) { - super.firstUpdated(changedProps); - this.hass.loadBackendTranslation("title"); - } - private _getItems = memoizeOne( ( mode: QuickBarMode, @@ -304,7 +299,8 @@ export class QuickBar extends LitElement { } else if (this._mode === QuickBarMode.Device) { this._deviceItems = this._deviceItems || this._generateDeviceItems(); } else { - this._entityItems = this._entityItems || this._generateEntityItems(); + this._entityItems = + this._entityItems || (await this._generateEntityItems()); } } @@ -581,9 +577,11 @@ export class QuickBar extends LitElement { ); } - private _generateEntityItems(): EntityItem[] { + private async _generateEntityItems(): Promise { const isRTL = computeRTL(this.hass); + await this.hass.loadBackendTranslation("title"); + return Object.keys(this.hass.states) .map((entityId) => { const stateObj = this.hass.states[entityId];