Skip to content

Commit

Permalink
Fix possible undefined entities pre-2023.4 (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
benct committed May 30, 2023
1 parent f4da92d commit acea63d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib/compute_state_display.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const computeStateDomain = (stateObj) => stateObj.entity_id.substr(0, sta

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

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

// Get entity with translation_key (post 2023.4.x)
const entity = entities && entities[stateObj.entity_id];

return (
(entity?.translation_key &&
localize(
Expand Down

0 comments on commit acea63d

Please sign in to comment.