Skip to content

Proposal: Lovelace strategies#6273

Closed
balloob wants to merge 5 commits into
devfrom
strategy-proposal
Closed

Proposal: Lovelace strategies#6273
balloob wants to merge 5 commits into
devfrom
strategy-proposal

Conversation

@balloob
Copy link
Copy Markdown
Member

@balloob balloob commented Jun 29, 2020

The other day I was on a call with @bramkragten and @zsarnett and we were talking frontend and we talked about LL dashboard generate strategies. Here is a proposal of how this could work. I just created the types, no actual implementations.

Adds:

  • Strategy to define dashboard
  • Strategy to define views
  • Allows defining custom strategies

This would allow people to share strategies that will create cards. People can add as many crazy options to their strategies as they wish.

The idea of strategies already exists in our codebase. If no Lovelace config exists, we will automatically generate one.

@balloob balloob marked this pull request as draft June 29, 2020 06:30
@balloob
Copy link
Copy Markdown
Member Author

balloob commented Jun 29, 2020

An example of a view strategy is a battery view strategy that will generate a view with all battery statuses grouped by rooms.

I can also see view strategies as a way for dashboard strategies to defer calculations until a user opens the view. So for example a strategy that creates a view per room would just generate a view config per room without actually sorting all the entities, as the view strategy can do that.


const tag = `ll-strategy-${name.substr(CUSTOM_PREFIX.length)}`;

return customElements.whenDefined(tag).then(() => customElements.get(tag));
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the awesome part of this. We will use the custom elements registry as a dependency manager.

Copy link
Copy Markdown
Contributor

@zsarnett zsarnett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome Idea. I am not sure of the technical if it will work but looks awesome

@zsarnett
Copy link
Copy Markdown
Contributor

zsarnett commented Nov 13, 2020

So I am trying to understand how we would get the strategy here.

const dashboardStrategy = await getLovelaceDashboardStrategy("default"); // using `get-strategy.ts
const dashboardStrategyInstance = new dashboardStrategy(); // Create an instance of the class
const dashboardConfig = await dashboardStrategyInstance.generateDashboard({ hass: this.hass!, lovelace: this.lovelace?.config }); // Call the function on the instance

This is how I am finding we would have to do this since we are using functions in the class. But I feel like I may be missing something.

@balloob
Copy link
Copy Markdown
Member Author

balloob commented Nov 18, 2020

The method will be defined as static methods, so we won't need to instantiate the strategy.

const dashboardStrategy = await getLovelaceDashboardStrategy("default");
const dashboardConfig = await dashboardStrategy.generateDashboard({ hass: this.hass!, lovelace: this.lovelace?.config }); // Call the function on the instance

@github-actions
Copy link
Copy Markdown

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
Thank you for your contributions.

@github-actions github-actions Bot added the stale label Feb 16, 2021
@github-actions github-actions Bot closed this Feb 23, 2021
@bramkragten bramkragten reopened this Mar 4, 2021
@github-actions github-actions Bot closed this Mar 11, 2021
@balloob balloob mentioned this pull request Apr 21, 2021
14 tasks
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants