Skip to content

Commit

Permalink
Add floor
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya committed Sep 18, 2024
1 parent af63b9a commit 5456a65
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/common/entity/compute_entity_name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
};
5 changes: 5 additions & 0 deletions src/common/entity/compute_floor_name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { FloorRegistryEntry } from "../../data/floor_registry";

export const computeFloorName = (
floor: FloorRegistryEntry
): string | undefined => floor.name?.trim();
10 changes: 10 additions & 0 deletions src/components/entity/ha-entity-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { computeDomain } from "../../common/entity/compute_domain";
import {
computeEntityAreaName,
computeEntityDeviceName,
computeEntityFloorName,
computeEntityFullName,
computeEntityName,
} from "../../common/entity/compute_entity_name";
Expand Down Expand Up @@ -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,
Expand All @@ -372,6 +380,7 @@ export class HaEntityPicker extends LitElement {
const entityContext = [
entityName !== deviceName ? deviceName : undefined,
areaName,
floorName,
]
.filter(Boolean)
.join(" ⸱ ");
Expand All @@ -384,6 +393,7 @@ export class HaEntityPicker extends LitElement {
displayedName ?? "",
areaName ?? "",
deviceName ?? "",
floorName ?? "",
].filter(Boolean),
entity_name: entityName,
entity_context: entityContext,
Expand Down
17 changes: 16 additions & 1 deletion src/dialogs/more-info/ha-more-info-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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)
: "";
Expand All @@ -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(" ⸱ ");

Expand Down

0 comments on commit 5456a65

Please sign in to comment.