diff --git a/src/common/entity/compute_entity_name.ts b/src/common/entity/compute_entity_name.ts index 86dd0a096b..ca57842d8b 100644 --- a/src/common/entity/compute_entity_name.ts +++ b/src/common/entity/compute_entity_name.ts @@ -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; diff --git a/test/common/entity/compute_entity_name.test.ts b/test/common/entity/compute_entity_name.test.ts index 978e009dc3..9fa36eeb9c 100644 --- a/test/common/entity/compute_entity_name.test.ts +++ b/test/common/entity/compute_entity_name.test.ts @@ -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(); + }); });