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

Take convert of blueprint automation and script #21151

Merged
merged 6 commits into from
Jun 26, 2024
Merged

Conversation

bramkragten
Copy link
Member

@bramkragten bramkragten commented Jun 24, 2024

Proposed change

CleanShot 2024-06-26 at 10 42 35

CleanShot 2024-06-26 at 10 42 45

Adds the ability to convert a blueprint automation and script to a normal automation or script

Needs: home-assistant/core#119890

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:

Summary by CodeRabbit

  • New Features

    • Added blueprint substitution functionality in automations and scripts.
    • Introduced a new method for users to take control of blueprints in automation and script editors.
  • UI Enhancements

    • Added new icons (e.g., mdiFileEdit) for better visual representation.
  • Localization

    • Added new translation keys for better user guidance when taking control of blueprints.

@bramkragten bramkragten added the Needs UX Pull requests requiring a review from the Home Assistant design team label Jun 24, 2024
Copy link
Contributor

coderabbitai bot commented Jun 24, 2024

Walkthrough

Walkthrough

These updates introduce new functions and configurations related to blueprint substitutions in multiple files across the system. They include importing necessary configurations, implementing blueprint substitution functions, and handling automation and script configurations within editors. Additionally, new translation keys were added to provide better user guidance for taking control of blueprints.

Changes

Files Change Summary
src/data/blueprint.ts Added imports for ManualAutomationConfig and ManualScriptConfig, introduced BlueprintSubstituteResults interface, and included substituteBlueprint function.
src/panels/config/automation/ha-automation-editor.ts, ... Added mdiFileEdit, BlueprintAutomationConfig, normalizeAutomationConfig, and substituteBlueprint. Implemented _takeControl method and adjusted configuration handling. Removed _normalizeConfig method.
src/panels/config/script/ha-script-editor.ts Added mdiFileEdit, BlueprintScriptConfig, and substituteBlueprint. Implemented _takeControl method for handling blueprint configurations.
src/panels/config/automation/blueprint-automation-editor.ts Changes related to substituting blueprints in automation configurations, including new imports, function definitions like substituteBlueprint, and control flow adjustments for handling unsaved changes.
src/panels/config/script/blueprint-script-editor.ts Reordered imports, moving BlueprintScriptConfig after ha-markdown.
src/translations/en.json Added new key "take_control" and associated confirmation messages for taking control of automation and scripts.

Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 9541475 and ed91c9d.

Files selected for processing (2)
  • src/panels/config/automation/blueprint-automation-editor.ts (1 hunks)
  • src/panels/config/script/blueprint-script-editor.ts (1 hunks)
Additional comments not posted (5)
src/panels/config/script/blueprint-script-editor.ts (3)

5-5: Import is correctly used.

The import of ha-markdown is effectively utilized in the rendering function of the class.


7-7: Import is correctly used.

The import of BlueprintScriptConfig is essential for typing the config property of the class.


Line range hint 9-36: Class implementation is correct and well-structured.

The HaBlueprintScriptEditor class is well-implemented with proper use of properties and methods.

src/panels/config/automation/blueprint-automation-editor.ts (2)

6-6: Import is correctly used.

The import of ha-markdown is effectively utilized in the rendering function of the class.


Line range hint 8-50: Class implementation is correct and well-structured.

The HaBlueprintAutomationEditor class is well-implemented with proper use of properties and methods.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 8

Outside diff range comments (3)
src/panels/config/blueprint/blueprint-generic-editor.ts (1)

Line range hint 220-220: Specify a more explicit type instead of any.

Using any disables TypeScript's type checking, which can lead to potential bugs and less maintainable code. It's advisable to specify a more explicit type for better type safety.

- const target = ev.target as any;
+ const target = ev.target as HTMLInputElement;  // Assuming the target is an input element.
src/panels/config/automation/ha-automation-editor.ts (2)

Line range hint 345-359: Clarify the role of the dirty and readOnly properties in context.

The dirty and readOnly properties are used in multiple components. It's important to document these properties within the class to clarify their roles, especially how they interact with UI state and data handling.


Line range hint 449-458: Refactor to improve readability and reduce complexity.

The method handling the loading and normalization of automation config is complex and could be simplified. Consider breaking it down into smaller, more manageable methods.

- this._config = {
-   ...baseConfig,
-   ...(initData ? normalizeAutomationConfig(initData) : initData),
- } as AutomationConfig;
+ this._initializeConfig(baseConfig, initData);

private _initializeConfig(baseConfig: Partial<AutomationConfig>, initData?: Partial<AutomationConfig>) {
  this._config = {
    ...baseConfig,
    ...(initData ? normalizeAutomationConfig(initData) : initData),
  } as AutomationConfig;
}

src/translations/en.json Outdated Show resolved Hide resolved
src/panels/config/blueprint/blueprint-generic-editor.ts Outdated Show resolved Hide resolved
src/panels/config/automation/ha-automation-editor.ts Outdated Show resolved Hide resolved
src/panels/config/automation/ha-automation-editor.ts Outdated Show resolved Hide resolved
@frenck frenck added the Noteworthy Marks a PR as noteworthy and should be in the release notes (in case it normally would not appear) label Jun 25, 2024
@piitaya piitaya marked this pull request as draft June 25, 2024 16:24
@piitaya piitaya marked this pull request as draft June 25, 2024 16:24
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

@piitaya piitaya marked this pull request as ready for review June 26, 2024 08:43
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

src/data/blueprint.ts Show resolved Hide resolved
src/panels/config/script/ha-script-editor.ts Show resolved Hide resolved
@piitaya piitaya changed the title WIP: Blueprint convert Take convert of blueprint automation and script Jun 26, 2024
Copy link
Member Author

@bramkragten bramkragten left a comment

Choose a reason for hiding this comment

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

@bramkragten bramkragten removed the Needs UX Pull requests requiring a review from the Home Assistant design team label Jun 26, 2024
@bramkragten bramkragten merged commit 55b6625 into dev Jun 26, 2024
13 checks passed
@bramkragten bramkragten deleted the blueprint-convert branch June 26, 2024 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed Noteworthy Marks a PR as noteworthy and should be in the release notes (in case it normally would not appear)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants