lovelace-mushroom icon indicating copy to clipboard operation
lovelace-mushroom copied to clipboard

[Bug]: Gracefully handle unknown (unavailable) entities - when state object is missing in hass.states

Open kulmegil opened this issue 2 years ago • 4 comments

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

  1. Create any mushroom card related to an entity
  2. 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?

js_error

kulmegil avatar Jul 10 '22 20:07 kulmegil

This issue significantly affects frontend performance

areyoufserious avatar Jul 14 '22 03:07 areyoufserious

I'm working on a fix. How should this be handled?

  1. Make the card be nothing
  2. Pretend the entity has an unknown state image image
  3. Make a custom error card to show in place of it

KTibow avatar Jul 19 '22 14:07 KTibow

It think just render null is enough for now. It's already the case but maybe there is some missing checks.

piitaya avatar Jul 19 '22 16:07 piitaya

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.

KTibow avatar Jul 19 '22 16:07 KTibow

Any update on this, just recently came across what looks to be the same issue; happy to test or support if needed.

image

shbatm avatar Apr 20 '23 15:04 shbatm