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

Convert this card to a strategy #38

Open
balloob opened this issue Apr 24, 2021 · 3 comments
Open

Convert this card to a strategy #38

balloob opened this issue Apr 24, 2021 · 3 comments

Comments

@balloob
Copy link

balloob commented Apr 24, 2021

In Home Assistant 2021.5 we're going to introduce strategies. A strategy is a JavaScript block that is executed on the loaded configuration before the dashboard as a whole or a specific view is being rendered.

It is the right spot to pre-process configurations and replace templates etc. The exact thing that decluttering-card does.

In the case of decluttering-card:

  • In generate dashboard add the decluttering strategy to each view.
  • In generate view apply all the templates.

An example of a strategy is here: https://gist.github.com/balloob/bf2715efba46420d6ba1a01586946308 . Note, this example is purely generating a configuration, but as you can see, the original configuration is passed in as info.config.

You will be able to play with a preview of this in the April 24 nightly.

@RomRider
Copy link
Collaborator

Great stuff! Thanks.

Reading the gist, my understanding is that I'd have to loop over all cards, cards with cards inside and stacks etc... of the view to check if they need to be processed (else it would be quite slow...) in generateView? How would I know how to iterate over abstract objects (cards config) and find cards?

Also, would it still work if the user wants to use another strategy in addition to this one?

What would happen in the card editor with this new method?

@balloob
Copy link
Author

balloob commented Apr 24, 2021

Right, you won't know the format of nested cards. I would indeed loop over a view inside generateView and then process it.

Right now we only allow a single strategy.

@balloob
Copy link
Author

balloob commented Apr 24, 2021

Oh and card editors are not supported, it will open a YAML editor because it's a strategy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants