diff --git a/src/common/entity/get_entity_context.ts b/src/common/entity/get_entity_context.ts index b08e2d20a9..a3d7b8a05b 100644 --- a/src/common/entity/get_entity_context.ts +++ b/src/common/entity/get_entity_context.ts @@ -1,7 +1,11 @@ import type { HassEntity } from "home-assistant-js-websocket"; import type { AreaRegistryEntry } from "../../data/area_registry"; import type { DeviceRegistryEntry } from "../../data/device_registry"; -import type { EntityRegistryDisplayEntry } from "../../data/entity_registry"; +import type { + EntityRegistryDisplayEntry, + EntityRegistryEntry, + ExtEntityRegistryEntry, +} from "../../data/entity_registry"; import type { FloorRegistryEntry } from "../../data/floor_registry"; import type { HomeAssistant } from "../../types"; @@ -19,6 +23,23 @@ export const getEntityContext = ( | EntityRegistryDisplayEntry | undefined; + if (!entry) { + return { + device: null, + area: null, + floor: null, + }; + } + return getEntityEntryContext(entry, hass); +}; + +export const getEntityEntryContext = ( + entry: + | EntityRegistryDisplayEntry + | EntityRegistryEntry + | ExtEntityRegistryEntry, + hass: HomeAssistant +): EntityContext => { const deviceId = entry?.device_id; const device = deviceId ? hass.devices[deviceId] : null; const areaId = entry?.area_id || device?.area_id; diff --git a/src/dialogs/more-info/ha-more-info-dialog.ts b/src/dialogs/more-info/ha-more-info-dialog.ts index 19f79acb0e..c00c9438b4 100644 --- a/src/dialogs/more-info/ha-more-info-dialog.ts +++ b/src/dialogs/more-info/ha-more-info-dialog.ts @@ -21,8 +21,10 @@ import { stopPropagation } from "../../common/dom/stop_propagation"; import { computeAreaName } from "../../common/entity/compute_area_name"; import { computeDeviceName } from "../../common/entity/compute_device_name"; import { computeDomain } from "../../common/entity/compute_domain"; -import { computeEntityName } from "../../common/entity/compute_entity_name"; -import { getEntityContext } from "../../common/entity/get_entity_context"; +import { + computeEntityEntryName, + computeEntityName, +} from "../../common/entity/compute_entity_name"; import { shouldHandleRequestSelectedEvent } from "../../common/mwc/handle-request-selected-event"; import { navigate } from "../../common/navigate"; import "../../components/ha-button-menu"; @@ -56,6 +58,10 @@ import "./ha-more-info-history-and-logbook"; import "./ha-more-info-info"; import "./ha-more-info-settings"; import "./more-info-content"; +import { + getEntityContext, + getEntityEntryContext, +} from "../../common/entity/get_entity_context"; export interface MoreInfoDialogParams { entityId: string | null; @@ -293,11 +299,18 @@ export class MoreInfoDialog extends LitElement { this._initialView !== DEFAULT_VIEW && !this._childView; const showCloseIcon = isDefaultView || isSpecificInitialView; - const context = stateObj ? getEntityContext(stateObj, this.hass) : null; + const context = stateObj + ? getEntityContext(stateObj, this.hass) + : this._entry + ? getEntityEntryContext(this._entry, this.hass) + : undefined; const entityName = stateObj ? computeEntityName(stateObj, this.hass) - : undefined; + : this._entry + ? computeEntityEntryName(this._entry, this.hass) + : entityId; + const deviceName = context?.device ? computeDeviceName(context.device) : undefined;