mirror of
https://github.com/home-assistant/frontend.git
synced 2025-12-19 18:28:42 +00:00
* 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:
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user