vacuum-card icon indicating copy to clipboard operation
vacuum-card copied to clipboard

Ensure getAttributes().status is always string

Open ristomatti opened this issue 4 months ago • 0 comments

After upgrading to Home Assistant 2024.2.4, vacuum-card didn't render due to null reference. The error shown on the console:

    Uncaught (in promise) TypeError: Cannot read properties of null (reading 'toLowerCase')
        at qr.renderStatus (vacuum-card.js?hacstag=261291295280:4:14674)
        at qr.render (vacuum-card.js?hacstag=261291295280:4:17680)
        at qr.update (vacuum-card.js?hacstag=261291295280:1:15173)
        at qr.performUpdate (vacuum-card.js?hacstag=261291295280:1:6493)
        at qr.scheduleUpdate (vacuum-card.js?hacstag=261291295280:1:6140)
        at qr._$Ej (vacuum-card.js?hacstag=261291295280:1:6048)

Based on the types, both status and state attributes can be undefined, while the state on the entity itself always has a string value. By reorganizing the return value of getAttributes, we ensure the derived status won't get overwritten by an undefined entity.attributes.status.

Fixes #699.

Aside: I had difficulty getting the actual change in a separate commit as the precommit hook reformatted the file every time. I've included the formatting in a separate commit. I noticed running npm run format would also format other files as well.

ristomatti avatar Feb 29 '24 21:02 ristomatti