custom-cards / decluttering-card

🧹 Declutter your lovelace configuration with the help of this card
MIT License
386 stars 30 forks source link

Convert this card to a strategy #38

Open balloob opened 3 years ago

balloob commented 3 years ago

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:

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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