vacuum-card
vacuum-card copied to clipboard
Ensure getAttributes().status is always string
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.