lovelace-mushroom
lovelace-mushroom copied to clipboard
[Bug]: Gracefully handle unknown (unavailable) entities - when state object is missing in hass.states
Current Behavior
When entity state is not available in hass.states lot's of JS errors are spammed. This can happen when e.g.
- "legacy" integration fails to setup entity without uniqueId (read-only entity).
- user changed entity_id without performing changes to lovelace config.
Card is not rendered.
Expected Behavior
Gracefully handle situation without throwing JS errors.
Render empty "unavailable" card (e.g. using entity_id as primary text). Or display "error card".
Steps To Reproduce
- Create any mushroom card related to an entity
- Set entity_id to non existing entity (or change entity_ids after creating card)
Environment
- OS: Windows / Android
- Browser: Chrome / Firefox / native app
- Version: any
- Hassio: 2022.7
Anything else?
This issue significantly affects frontend performance
I'm working on a fix. How should this be handled?
- Make the card be nothing
- Pretend the entity has an unknown state
- Make a custom error card to show in place of it
It think just render null
is enough for now. It's already the case but maybe there is some missing checks.
https://github.com/piitaya/lovelace-mushroom/blob/588a9ea5c74ae527c35dadde4d4e474fb24e6d02/src/cards/entity-card/entity-card.ts#L81-L84
If the entity doesn't exist, it tries to get attributes, which is null, so it does null.friendly_name
.
Any update on this, just recently came across what looks to be the same issue; happy to test or support if needed.