diff --git a/src/components/ha-related-items.ts b/src/components/ha-related-items.ts
index 8b53feaddf..0bed712acd 100644
--- a/src/components/ha-related-items.ts
+++ b/src/components/ha-related-items.ts
@@ -1,6 +1,10 @@
import "@material/mwc-list/mwc-list";
-import { mdiDevices, mdiPaletteSwatch, mdiSofa } from "@mdi/js";
-import { HassEntity } from "home-assistant-js-websocket";
+import {
+ mdiAlertCircleOutline,
+ mdiDevices,
+ mdiPaletteSwatch,
+ mdiSofa,
+} from "@mdi/js";
import {
css,
CSSResultGroup,
@@ -11,10 +15,11 @@ import {
} from "lit";
import { customElement, property, state } from "lit/decorators";
import { styleMap } from "lit/directives/style-map";
+import memoizeOne from "memoize-one";
import { fireEvent } from "../common/dom/fire_event";
+import { caseInsensitiveStringCompare } from "../common/string/compare";
import { Blueprints, fetchBlueprints } from "../data/blueprint";
import { ConfigEntry, getConfigEntries } from "../data/config_entries";
-import { SceneEntity } from "../data/scene";
import { findRelated, ItemType, RelatedResult } from "../data/search";
import { haStyle } from "../resources/styles";
import { HomeAssistant } from "../types";
@@ -72,13 +77,55 @@ export class HaRelatedItems extends LitElement {
}
}
+ private _relatedEntities = memoizeOne((entityIds: string[]) =>
+ this._toEntities(entityIds)
+ );
+
+ private _relatedAutomations = memoizeOne((automationEntityIds: string[]) =>
+ this._toEntities(automationEntityIds)
+ );
+
+ private _relatedScripts = memoizeOne((scriptEntityIds: string[]) =>
+ this._toEntities(scriptEntityIds)
+ );
+
+ private _relatedGroups = memoizeOne((groupEntityIds: string[]) =>
+ this._toEntities(groupEntityIds)
+ );
+
+ private _relatedScenes = memoizeOne((sceneEntityIds: string[]) =>
+ this._toEntities(sceneEntityIds)
+ );
+
+ private _toEntities = (entityIds: string[]) =>
+ entityIds
+ .map((entityId) => this.hass.states[entityId])
+ .filter((entity) => entity)
+ .sort((a, b) =>
+ caseInsensitiveStringCompare(
+ a.attributes.friendly_name ?? a.entity_id,
+ b.attributes.friendly_name ?? b.entity_id,
+ this.hass.language
+ )
+ );
+
protected render() {
if (!this._related) {
return nothing;
}
if (Object.keys(this._related).length === 0) {
return html`
- ${this.hass.localize("ui.components.related-items.no_related_found")}
+
+
+
+ ${this.hass.localize(
+ "ui.components.related-items.no_related_found"
+ )}
+
+
`;
}
return html`
@@ -92,7 +139,7 @@ export class HaRelatedItems extends LitElement {
(configEntry) => configEntry.entry_id === relatedConfigEntryId
);
if (!entry) {
- return "";
+ return nothing;
}
return html`
`
- : ""}
+ : nothing}
${this._related.device
? html`