diff --git a/src/common/entity/compute_entity_name.ts b/src/common/entity/compute_entity_name.ts index 54f8053bc051..9de44644e58c 100644 --- a/src/common/entity/compute_entity_name.ts +++ b/src/common/entity/compute_entity_name.ts @@ -5,6 +5,7 @@ import { stripPrefixFromEntityName } from "./strip_prefix_from_entity_name"; import { computeStateName } from "./compute_state_name"; import { computeDeviceName } from "./compute_device_name"; import { computeAreaName } from "./compute_area_name"; +import { computeFloorName } from "./compute_floor_name"; export const computeEntityFullName = ( stateObj: HassEntity, @@ -85,3 +86,22 @@ export const computeEntityAreaName = ( return area ? computeAreaName(area) : undefined; }; + +export const computeEntityFloorName = ( + stateObj: HassEntity, + entities: HomeAssistant["entities"], + devices: HomeAssistant["devices"], + areas: HomeAssistant["areas"], + floors: HomeAssistant["floors"] +): string | undefined => { + const entry = entities[stateObj.entity_id] as + | EntityRegistryDisplayEntry + | undefined; + const device = entry?.device_id ? devices[entry?.device_id] : undefined; + + const areaId = entry?.area_id || device?.area_id; + const area = areaId ? areas[areaId] : undefined; + const floor = area?.floor_id ? floors[area?.floor_id] : undefined; + + return floor ? computeFloorName(floor) : undefined; +}; diff --git a/src/common/entity/compute_floor_name.ts b/src/common/entity/compute_floor_name.ts new file mode 100644 index 000000000000..e6355cdb216d --- /dev/null +++ b/src/common/entity/compute_floor_name.ts @@ -0,0 +1,5 @@ +import { FloorRegistryEntry } from "../../data/floor_registry"; + +export const computeFloorName = ( + floor: FloorRegistryEntry +): string | undefined => floor.name?.trim(); diff --git a/src/components/entity/ha-entity-picker.ts b/src/components/entity/ha-entity-picker.ts index a988f8294c45..ecd831e562d9 100644 --- a/src/components/entity/ha-entity-picker.ts +++ b/src/components/entity/ha-entity-picker.ts @@ -8,6 +8,7 @@ import { computeDomain } from "../../common/entity/compute_domain"; import { computeEntityAreaName, computeEntityDeviceName, + computeEntityFloorName, computeEntityFullName, computeEntityName, } from "../../common/entity/compute_entity_name"; @@ -354,6 +355,13 @@ export class HaEntityPicker extends LitElement { hass.devices, hass.areas ); + const floorName = computeEntityFloorName( + stateObj, + hass.entities, + hass.devices, + hass.areas, + hass.floors + ); const deviceName = computeEntityDeviceName( stateObj, hass.entities, @@ -372,6 +380,7 @@ export class HaEntityPicker extends LitElement { const entityContext = [ entityName !== deviceName ? deviceName : undefined, areaName, + floorName, ] .filter(Boolean) .join(" ⸱ "); @@ -384,6 +393,7 @@ export class HaEntityPicker extends LitElement { displayedName ?? "", areaName ?? "", deviceName ?? "", + floorName ?? "", ].filter(Boolean), entity_name: entityName, entity_context: entityContext, diff --git a/src/dialogs/more-info/ha-more-info-dialog.ts b/src/dialogs/more-info/ha-more-info-dialog.ts index cab1971d1fc9..e5200146aab0 100644 --- a/src/dialogs/more-info/ha-more-info-dialog.ts +++ b/src/dialogs/more-info/ha-more-info-dialog.ts @@ -21,6 +21,7 @@ import { computeDomain } from "../../common/entity/compute_domain"; import { computeEntityAreaName, computeEntityDeviceName, + computeEntityFloorName, computeEntityName, } from "../../common/entity/compute_entity_name"; import { shouldHandleRequestSelectedEvent } from "../../common/mwc/handle-request-selected-event"; @@ -293,6 +294,16 @@ export class MoreInfoDialog extends LitElement { ) : ""; + const floorName = stateObj + ? computeEntityFloorName( + stateObj, + this.hass.entities, + this.hass.devices, + this.hass.areas, + this.hass.floors + ) + : ""; + const deviceName = stateObj ? computeEntityDeviceName(stateObj, this.hass.entities, this.hass.devices) : ""; @@ -301,7 +312,11 @@ export class MoreInfoDialog extends LitElement { const subtitle = this._childView?.viewTitle ? undefined - : [entityName !== deviceName ? deviceName : undefined, areaName] // Do not include device name if it's the same as entity name + : [ + entityName !== deviceName ? deviceName : undefined, + areaName, + floorName, + ] // Do not include device name if it's the same as entity name .filter(Boolean) .join(" ⸱ ");