Skip to content

Commit acea63d

Browse files
committed
Fix possible undefined entities pre-2023.4 (benct#293)
1 parent f4da92d commit acea63d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/lib/compute_state_display.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export const computeStateDomain = (stateObj) => stateObj.entity_id.substr(0, sta
1010

1111
export const computeStateDisplay = (localize, stateObj, locale, entities, state) => {
1212
const compareState = state !== undefined ? state : stateObj.state;
13-
const entity = entities[stateObj.entity_id];
1413

1514
if (compareState === UNKNOWN || compareState === UNAVAILABLE) {
1615
return localize(`state.default.${compareState}`);
@@ -104,6 +103,9 @@ export const computeStateDisplay = (localize, stateObj, locale, entities, state)
104103
return formatDateTime(new Date(compareState), locale);
105104
}
106105

106+
// Get entity with translation_key (post 2023.4.x)
107+
const entity = entities && entities[stateObj.entity_id];
108+
107109
return (
108110
(entity?.translation_key &&
109111
localize(

0 commit comments

Comments
 (0)