Skip to content

Commit 88f84f7

Browse files
committed
Add floor
1 parent 0b99898 commit 88f84f7

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

src/common/entity/compute_entity_name.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { stripPrefixFromEntityName } from "./strip_prefix_from_entity_name";
55
import { computeStateName } from "./compute_state_name";
66
import { computeDeviceName } from "./compute_device_name";
77
import { computeAreaName } from "./compute_area_name";
8+
import { computeFloorName } from "./compute_floor_name";
89

910
export const computeEntityFullName = (
1011
stateObj: HassEntity,
@@ -85,3 +86,22 @@ export const computeEntityAreaName = (
8586

8687
return area ? computeAreaName(area) : undefined;
8788
};
89+
90+
export const computeEntityFloorName = (
91+
stateObj: HassEntity,
92+
entities: HomeAssistant["entities"],
93+
devices: HomeAssistant["devices"],
94+
areas: HomeAssistant["areas"],
95+
floors: HomeAssistant["floors"]
96+
): string | undefined => {
97+
const entry = entities[stateObj.entity_id] as
98+
| EntityRegistryDisplayEntry
99+
| undefined;
100+
const device = entry?.device_id ? devices[entry?.device_id] : undefined;
101+
102+
const areaId = entry?.area_id || device?.area_id;
103+
const area = areaId ? areas[areaId] : undefined;
104+
const floor = area?.floor_id ? floors[area?.floor_id] : undefined;
105+
106+
return floor ? computeFloorName(floor) : undefined;
107+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { FloorRegistryEntry } from "../../data/floor_registry";
2+
3+
export const computeFloorName = (
4+
floor: FloorRegistryEntry
5+
): string | undefined => floor.name?.trim();

src/components/entity/ha-entity-picker.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { computeDomain } from "../../common/entity/compute_domain";
99
import {
1010
computeEntityAreaName,
1111
computeEntityDeviceName,
12+
computeEntityFloorName,
1213
computeEntityFullName,
1314
computeEntityName,
1415
} from "../../common/entity/compute_entity_name";
@@ -343,6 +344,13 @@ export class HaEntityPicker extends LitElement {
343344
hass.devices,
344345
hass.areas
345346
);
347+
const floorName = computeEntityFloorName(
348+
stateObj,
349+
hass.entities,
350+
hass.devices,
351+
hass.areas,
352+
hass.floors
353+
);
346354
const deviceName = computeEntityDeviceName(
347355
stateObj,
348356
hass.entities,
@@ -361,6 +369,7 @@ export class HaEntityPicker extends LitElement {
361369
const entityContext = [
362370
entityName !== deviceName ? deviceName : undefined,
363371
areaName,
372+
floorName,
364373
]
365374
.filter(Boolean)
366375
.join(" ⸱ ");
@@ -373,6 +382,7 @@ export class HaEntityPicker extends LitElement {
373382
displayedName ?? "",
374383
areaName ?? "",
375384
deviceName ?? "",
385+
floorName ?? "",
376386
].filter(Boolean),
377387
entity_name: entityName,
378388
entity_context: entityContext,

src/dialogs/more-info/ha-more-info-dialog.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { computeDomain } from "../../common/entity/compute_domain";
2222
import {
2323
computeEntityAreaName,
2424
computeEntityDeviceName,
25+
computeEntityFloorName,
2526
computeEntityName,
2627
} from "../../common/entity/compute_entity_name";
2728
import { shouldHandleRequestSelectedEvent } from "../../common/mwc/handle-request-selected-event";
@@ -301,6 +302,16 @@ export class MoreInfoDialog extends LitElement {
301302
)
302303
: "";
303304

305+
const floorName = stateObj
306+
? computeEntityFloorName(
307+
stateObj,
308+
this.hass.entities,
309+
this.hass.devices,
310+
this.hass.areas,
311+
this.hass.floors
312+
)
313+
: "";
314+
304315
const deviceName = stateObj
305316
? computeEntityDeviceName(stateObj, this.hass.entities, this.hass.devices)
306317
: "";
@@ -309,7 +320,11 @@ export class MoreInfoDialog extends LitElement {
309320

310321
const subtitle = this._childView?.viewTitle
311322
? undefined
312-
: [entityName !== deviceName ? deviceName : undefined, areaName] // Do not include device name if it's the same as entity name
323+
: [
324+
entityName !== deviceName ? deviceName : undefined,
325+
areaName,
326+
floorName,
327+
] // Do not include device name if it's the same as entity name
313328
.filter(Boolean)
314329
.join(" ⸱ ");
315330

0 commit comments

Comments
 (0)