Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure getAttributes().status is always string #702

Merged
merged 2 commits into from Mar 7, 2024

Conversation

ristomatti
Copy link
Contributor

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.

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`.
@denysdovhan denysdovhan added the bug Something isn't working label Mar 7, 2024
@denysdovhan denysdovhan merged commit a25f254 into denysdovhan:master Mar 7, 2024
3 checks passed
@denysdovhan
Copy link
Owner

Thanks for a fix!

@Delfairen
Copy link

It appears this fixes the bug I created yesterday #714 can we get a release and do I need to close the bug to this PR?

@rrooggiieerr
Copy link

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

@DjRicko
Copy link

DjRicko commented Mar 10, 2024

@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
Copy link
Contributor Author

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
Copy link

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
Copy link
Contributor Author

@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 pushed a commit that referenced this pull request Mar 13, 2024
## [2.8.1](v2.8.0...v2.8.1) (2024-03-13)

### Bug Fixes

* Ensure getAttributes().status is always string ([#702](#702)) ([a25f254](a25f254))
* remove some conditions for release ([7945494](7945494))
* Update hu.json ([#605](#605)) ([1a92e99](1a92e99))
* Update ru.json ([#602](#602)) ([733ce63](733ce63))
* Updates to Finnish (fi) translation ([#608](#608)) ([584e19f](584e19f))
Copy link

🎉 This PR is included in version 2.8.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

After updating to 2024.2.4 is the card empty
5 participants