Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions src/common/entity/compute_entity_name_display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { HomeAssistant } from "../../types";
import { ensureArray } from "../array/ensure-array";
import { computeAreaName } from "./compute_area_name";
import { computeDeviceName } from "./compute_device_name";
import { computeEntityName, entityUseDeviceName } from "./compute_entity_name";
import { computeEntityName } from "./compute_entity_name";
import { computeFloorName } from "./compute_floor_name";
import { computeStateName } from "./compute_state_name";
import { getEntityContext } from "./context/get_entity_context";
Expand Down Expand Up @@ -46,7 +46,7 @@ export const computeEntityNameDisplay = (
return computeStateName(stateObj);
}

let items = ensureArray(name);
const items = ensureArray(name);

const separator = options?.separator ?? DEFAULT_SEPARATOR;

Expand All @@ -55,16 +55,6 @@ export const computeEntityNameDisplay = (
return items.map((item) => item.text).join(separator);
}

const useDeviceName = entityUseDeviceName(stateObj, entities, devices);

// If entity uses device name, and device is not already included, replace it with device name
if (useDeviceName) {
const hasDevice = items.some((n) => n.type === "device");
if (!hasDevice) {
items = items.map((n) => (n.type === "entity" ? { type: "device" } : n));
}
}

const names = computeEntityNameList(
stateObj,
items,
Expand Down
4 changes: 3 additions & 1 deletion src/components/entity/state-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class StateInfo extends LitElement {
return nothing;
}

const name = this.hass.formatEntityName(this.stateObj, { type: "entity" });
const name =
this.hass.formatEntityName(this.stateObj, { type: "entity" }) ||
this.hass.formatEntityName(this.stateObj, { type: "device" });

return html`<state-badge
.hass=${this.hass}
Expand Down
8 changes: 3 additions & 5 deletions test/common/entity/compute_entity_name_display.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe("computeEntityNameDisplay", () => {
expect(result).toBe("Kitchen Light");
});

it("replaces entity with device name when entity uses device name", () => {
it("returns empty for entity type when entity name is empty", () => {
const stateObj = mockStateObj({ entity_id: "light.kitchen" });
const hass = {
entities: {
Expand Down Expand Up @@ -138,10 +138,10 @@ describe("computeEntityNameDisplay", () => {
hass.floors
);

expect(result).toBe("Kitchen Device");
expect(result).toBe("");
});

it("does not replace entity with device when device is already included", () => {
it("returns device name when entity uses device name and device is included", () => {
const stateObj = mockStateObj({ entity_id: "light.kitchen" });
const hass = {
entities: {
Expand Down Expand Up @@ -170,8 +170,6 @@ describe("computeEntityNameDisplay", () => {
hass.floors
);

// Since entity name equals device name, entity returns undefined
// So we only get the device name
expect(result).toBe("Kitchen Device");
});

Expand Down
Loading