1
0
mirror of https://github.com/home-assistant/frontend.git synced 2025-12-19 18:28:42 +00:00

Revert "Default entity name to friendly name"

This reverts commit a607edca96.
This commit is contained in:
Paul Bottein
2025-10-29 13:02:55 +01:00
parent a607edca96
commit 89b9780345
19 changed files with 87 additions and 46 deletions

View File

@@ -1,4 +1,5 @@
import { describe, expect, it, vi } from "vitest";
import { DEFAULT_ENTITY_NAME } from "../../../../../src/common/entity/compute_entity_name_display";
import { computeLovelaceEntityName } from "../../../../../src/panels/lovelace/common/entity/compute-lovelace-entity-name";
import type { HomeAssistant } from "../../../../../src/types";
import { mockStateObj } from "../../../../common/entity/context/context-mock";
@@ -22,29 +23,30 @@ describe("computeLovelaceEntityName", () => {
expect(mockFormatEntityName).not.toHaveBeenCalled();
});
it("return state name when nameConfig is empty string", () => {
it("returns empty string when nameConfig is empty string", () => {
const mockFormatEntityName = vi.fn();
const hass = createMockHass(mockFormatEntityName);
const stateObj = mockStateObj({ entity_id: "light.kitchen" });
const result = computeLovelaceEntityName(hass, stateObj, "");
expect(result).toBe("Kitchen Light");
expect(result).toBe("");
expect(mockFormatEntityName).not.toHaveBeenCalled();
});
it("return state name when nameConfig is undefined", () => {
it("calls formatEntityName with DEFAULT_ENTITY_NAME when nameConfig is undefined", () => {
const mockFormatEntityName = vi.fn(() => "Formatted Name");
const hass = createMockHass(mockFormatEntityName);
const stateObj = mockStateObj({
entity_id: "light.kitchen",
attributes: { friendly_name: "Kitchen Light" },
});
const stateObj = mockStateObj({ entity_id: "light.kitchen" });
const result = computeLovelaceEntityName(hass, stateObj, undefined);
expect(result).toBe("Kitchen Light");
expect(mockFormatEntityName).not.toHaveBeenCalled();
expect(result).toBe("Formatted Name");
expect(mockFormatEntityName).toHaveBeenCalledTimes(1);
expect(mockFormatEntityName).toHaveBeenCalledWith(
stateObj,
DEFAULT_ENTITY_NAME
);
});
it("calls formatEntityName with EntityNameItem config", () => {