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

entities can not be a string. #44

Closed
bratanon opened this issue Feb 10, 2019 · 8 comments
Closed

entities can not be a string. #44

bratanon opened this issue Feb 10, 2019 · 8 comments
Labels
bug Something isn't working

Comments

@bratanon
Copy link

bratanon commented Feb 10, 2019

The docs state that the entities option can be string or list.

Using a string works in the UI, however it fails when using the "Unused entities page".

That script assumes that entities is a list, and not a string.

This will work in the ui, but not in the unused entities page

- type: custom:mini-graph-card
  entities: sensor.somesensor

This will work everywhere

- type: custom:mini-graph-card
  entities: 
    - sensor.somesensor
@kalkih
Copy link
Owner

kalkih commented Feb 10, 2019

Please elaborate, what do you mean it fails in the unused entities page?
Will it not register the entity as used or what's not working?

@bratanon
Copy link
Author

The console gives me this.

f98c2ed66c0dc1462a8d.chunk.js:formatted:22 Uncaught (in promise) TypeError: obj.entities.forEach is not a function
    at addEntities (f98c2ed66c0dc1462a8d.chunk.js:formatted:22)
    at obj.cards.forEach.card (f98c2ed66c0dc1462a8d.chunk.js:formatted:28)
    at Array.forEach (<anonymous>)
    at addEntities (f98c2ed66c0dc1462a8d.chunk.js:formatted:28)
    at obj.cards.forEach.card (f98c2ed66c0dc1462a8d.chunk.js:formatted:28)
    at Array.forEach (<anonymous>)
    at addEntities (f98c2ed66c0dc1462a8d.chunk.js:formatted:28)
    at config.views.forEach.view (f98c2ed66c0dc1462a8d.chunk.js:formatted:35)
    at Array.forEach (<anonymous>)
    at computeUsedEntities (f98c2ed66c0dc1462a8d.chunk.js:formatted:35)

The code behind this

.....
if (obj.entities) {
   obj.entities.forEach(entity=>addEntityId(entity))
}
......

I also noticed while reading the code for this card that it supports both entities and entity.

However most examples int he docs is using entities: sensor.illumination or simulare.
That will cause this error to happen. Instead it should be clear that if you only want to use one entity in the card, use entity or entities and with a list, not a string.

@bratanon
Copy link
Author

Steps to reproduce this is quite easy using the first simple example

  - type: custom:mini-graph-card
    entities: sensor.illumination

The go to your-url.com/lovelace/hass-unused-entities, then check the console.

@bratanon
Copy link
Author

Please elaborate, what do you mean it fails in the unused entities page?
Will it not register the entity as used or what's not working?

The page will be totally blank. No unused entites will be shown at all.

@kalkih kalkih added the bug Something isn't working label Feb 10, 2019
@kalkih
Copy link
Owner

kalkih commented Feb 10, 2019

The console gives me this.

Okay, interesting, I wasn't aware that HA had such a check, I've personally never used the "unused entities" UI.

However most examples int he docs is using entities: sensor.illumination or simulare.
That will cause this error to happen. Instead it should be clear that if you only want to use one entity in the card, use entity or entities and with a list, not a string.

The only reason the entity option is still supported in the code is for backwards compatibility reasons, for people that doesn't read the release notes, it's basically deprecated and therefore removed from the docs.

I don't want to leave both entity and entities options in, I guess I'll end up making a breaking change and require entities to be a list, similar to the core entities card, and remove the entity option completely.

Thanks for letting me know about this issue.

@bratanon
Copy link
Author

I see, i rarely us it either, however now I did and found this.

Unfortunately I think that a BC is necessary here.
What you can do to help the users is to throw an error that describes the situation in a small sentence.
Thrown errors are being read by the frontend and will be presented as a red card instead of the failing one.

@kalkih
Copy link
Owner

kalkih commented Feb 10, 2019

Great idea, I guess I could throw in a couple of check when setting the config, thanks!

@bratanon
Copy link
Author

Please let me know if I can help you test this or anything else.

Also, Im on the SHG discrod if you wanna get in touch quick.

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

No branches or pull requests

2 participants