From 4612acfbaff748fc16e6a835a21868414f1bff53 Mon Sep 17 00:00:00 2001 From: Jan-Philipp Benecke Date: Thu, 9 May 2024 13:25:29 +0200 Subject: [PATCH] Use domain translation in filter for domain search --- src/components/ha-filter-domains.ts | 32 +++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/components/ha-filter-domains.ts b/src/components/ha-filter-domains.ts index 442cfd41be68..16b5c2b1a8aa 100644 --- a/src/components/ha-filter-domains.ts +++ b/src/components/ha-filter-domains.ts @@ -12,6 +12,11 @@ import "./ha-domain-icon"; import "./search-input-outlined"; import { computeDomain } from "../common/entity/compute_domain"; +type DomainTranslation = { + domain: string; + translation: string; +}; + @customElement("ha-filter-domains") export class HaFilterDomains extends LitElement { @property({ attribute: false }) public hass!: HomeAssistant; @@ -63,17 +68,17 @@ export class HaFilterDomains extends LitElement { (i) => i, (domain) => html` - ${domainToName(this.hass.localize, domain)} + ${domain.translation} ` )} ` @@ -83,13 +88,22 @@ export class HaFilterDomains extends LitElement { } private _domains = memoizeOne((states, filter) => { - const domains = new Set(); + const domains = new Map(); Object.keys(states).forEach((entityId) => { - domains.add(computeDomain(entityId)); + const computedDomain = computeDomain(entityId); + domains.set(computedDomain, { + domain: computedDomain, + translation: domainToName(this.hass.localize, computedDomain), + }); }); - return Array.from(domains) - .filter((domain) => !filter || domain.toLowerCase().includes(filter)) - .sort((a, b) => stringCompare(a, b, this.hass.locale.language)); + + return Array.from(domains.values()) + .filter( + (entry) => !filter || entry.translation.toLowerCase().includes(filter) + ) + .sort((a, b) => + stringCompare(a.translation, b.translation, this.hass.locale.language) + ); }); protected updated(changed) {