1
0
mirror of https://github.com/home-assistant/frontend.git synced 2025-12-20 02:38:53 +00:00

Fix entities not showing due to JavaScript crash (fixes #25363) (#26599)

* Fix entity UI crash from undefined entity names (fixes #25363)

* Fix mock function type compatibility in test

- Update mock to handle string | undefined parameter
- Maintain test functionality while satisfying type checker

* Simplify approach based on reviewer feedback

- Use String() coercion to preserve numeric entity names (e.g., power strip outlets)
- Single line change instead of complex type validation across multiple files
- Revert stripPrefixFromEntityName to original (no longer needs null handling)
- Remove separate test file, update existing test to expect stringified numbers
- More conservative approach that preserves data rather than replacing with fallbacks
This commit is contained in:
Drinor Dalipi
2025-08-20 08:10:13 +02:00
committed by GitHub
parent 10dcc08068
commit 8b73d664b4
2 changed files with 29 additions and 1 deletions

View File

@@ -28,7 +28,10 @@ export const computeEntityEntryName = (
hass: HomeAssistant
): string | undefined => {
const name =
entry.name || ("original_name" in entry ? entry.original_name : undefined);
entry.name ||
("original_name" in entry && entry.original_name != null
? String(entry.original_name)
: "");
const device = entry.device_id ? hass.devices[entry.device_id] : undefined;

View File

@@ -134,4 +134,29 @@ describe("computeEntityEntryName", () => {
};
expect(computeEntityEntryName(entry as any, hass as any)).toBeUndefined();
});
it("handles entities with numeric original_name (real bug from issue #25363)", () => {
vi.spyOn(computeDeviceNameModule, "computeDeviceName").mockReturnValue(
"Texas Instruments CC2652"
);
const entry = {
entity_id: "sensor.texas_instruments_cc2652_2",
name: null, // null name
original_name: 2, // Number instead of string! This caused the original crash
device_id: "dev1",
has_entity_name: true,
};
const hass = {
devices: { dev1: {} },
states: {},
};
// Should not throw an error and should return the stringified number
expect(() =>
computeEntityEntryName(entry as any, hass as any)
).not.toThrow();
expect(computeEntityEntryName(entry as any, hass as any)).toBe("2");
vi.restoreAllMocks();
});
});