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

Refactor strategy foundation #17921

Merged
merged 5 commits into from
Sep 21, 2023
Merged

Refactor strategy foundation #17921

merged 5 commits into from
Sep 21, 2023

Conversation

piitaya
Copy link
Member

@piitaya piitaya commented Sep 14, 2023

Proposed change

This PR changes the way to define strategies. original-states and energy strategies has been migrated to the new API.

Dashboard and view strategies has been split into 2 class. This class share the same interface so we can easily extends it to other elements (section within a view for example). Also a config editor can be easily added by adding getConfigElement method to the class (#17916 will be edited with this changes)

Config format

The options has been moved to the root (to be consistent with card config). Backward compatibility for current custom strategies has been added with a drawback : options property can not be used.

Before

strategy:
  type: original-states
  options:
    foo: bar
views: []

After

strategy:
  type: original-states
  foo: bar
views: []

Generate method parameters

  • config: the user configuration of the strategy with options.
    { 
      type: "energy",
      show_date_selection: true
    }
  • hass: Home Assistant object
  • params: custom parameters injected by the frontend (e.g. narrow)

Before

class DemoStrategy {
    static generateView({
        view,
        config,
        hass,
        narrow
    })
    static generateDashboard({
        config,
        hass,
        narrow
    })
}

After

class DemoDashboardStrategy {
    static generate(config, hass, params)
}

class DemoViewStrategy {
    static generate(config, hass, params)
}

Note

I kept the custom element registry for storing the strategies (and custom ones) even if it's not valid because it will be easier for developer to have similar way to register strategies than cards.
A backward compatibility has been added to avoid issues with custom strategies that are not using the new format.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue or discussion:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

@github-actions github-actions bot added the Cast Related to Home Assistant Cast UI label Sep 14, 2023
@piitaya piitaya marked this pull request as ready for review September 14, 2023 14:09
@piitaya piitaya force-pushed the refactor_strategy_foundation branch from 9d69d65 to 584f083 Compare September 20, 2023 19:12
@piitaya piitaya merged commit 9217d5b into dev Sep 21, 2023
8 checks passed
@piitaya piitaya deleted the refactor_strategy_foundation branch September 21, 2023 18:22
@github-actions github-actions bot locked and limited conversation to collaborators Sep 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Cast Related to Home Assistant Cast UI cla-signed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants