denysdovhan / vacuum-card

Vacuum cleaner card for Home Assistant Lovelace UI
https://denysdovhan.com/smart-home
MIT License
903 stars 529 forks source link

Ensure getAttributes().status is always string #702

Closed ristomatti closed 6 months ago

ristomatti commented 6 months ago

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.

denysdovhan commented 6 months ago

Thanks for a fix!

Delfairen commented 6 months ago

It appears this fixes the bug I created yesterday https://github.com/denysdovhan/vacuum-card/issues/714 can we get a release and do I need to close the bug to this PR?

rrooggiieerr commented 6 months ago

@denysdovhan I think you need to release a new version so it can be installed/upgraded trough HACS

DjRicko commented 6 months ago

@denysdovhan I think you need to release a new version so it can be installed/upgraded trough HACS

Yeah i was just about to post here that we need a release for people to get automated updates.

ristomatti commented 6 months ago

Please give the man some slack, this is FOSS after all. There's a workaround as I've mentioned here and here. So there's no hurry. 😄

rrooggiieerr commented 6 months ago

No pressure, just putting something under attention which might have been overseen. Using a forked repository as a quick fix is not a sustainable solution imho, plenty of people will forget to revert back to the original repository once a new release is made and who's going to guarantee that the fork will be maintained? Better to just download the master zip file and upload the contents to the www/community/ folder

ristomatti commented 6 months ago

@rrooggiieerr It won't be maintained but it will exist at least until a fixed version will be released as I'm using it myself. I recommend everyone using it to subscribe to release notifications for this repo to know when to change it back.

github-actions[bot] commented 5 months ago

:tada: This PR is included in version 2.8.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: