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

Add sequence action for automations & scripts #117690

Merged
merged 2 commits into from
May 24, 2024
Merged

Add sequence action for automations & scripts #117690

merged 2 commits into from
May 24, 2024

Conversation

frenck
Copy link
Member

@frenck frenck commented May 18, 2024

Proposed change

Context: It came out of a discussion with the UX & frontend team @ Nabu Casa when we where talking about this frontend PR: home-assistant/frontend#18470

This PR adds a new script action that can be used in automations and scripts: sequence.

The sequence action allows a user to group one of more actions into its own sequence. For example:

automation:
  - trigger:
      - platform: state
        entity_id: binary_sensor.motion
        to: "on"
    action:
      - alias: "Group of actions"
        sequence:
          - ...
          - ...
      - ...

This might not sound helpful at first, but it has quite a few use cases.

Organizing: Each sequence group can be named, but also enabled/disabled. From the automation editor perspective, a group of actions can be collapsed.

Blueprints: When using the actions selector, the author of a blueprint can ask a user for one or more action to take. However, the author of a blueprint will never be able to combine it with predefined actions (as lists in YAML are not mergable). This will now work:

automation:
  - trigger:
      - platform: state
        entity_id: binary_sensor.motion
        to: "on"
    action:
      - alias: "Some build in action"
        service: ...
      - sequence: !input user_provided_additiona_actions_from_blueprint

YAML Anchors: For our power users, YAML anchors and lists are hard. Again, lists are not mergeable, so this means it is also harder for YAML users to re-use lists of sequences. With the above, it provides a way to still be able to do this.

automation:
  - trigger:
      - platform: state
        entity_id: binary_sensor.motion
        to: "on"
    action:
      - alias: "Some action"
        service: ...
      - sequence: *anchored_list_of_actions

Parallel action: The source of this all, can be found in this PR. When the sequence action is added like is done in this PR, it becomes a generic available building block. Meaning that most of the "weirdness" or specific things done in making the UI for parallel action with sequence work... will just work without much special handling.

Type of change

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

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

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

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@frenck frenck marked this pull request as ready for review May 21, 2024 09:22
@frenck frenck requested a review from a team as a code owner May 21, 2024 09:22
Co-authored-by: Robert Resch <robert@resch.dev>
@frenck
Copy link
Member Author

frenck commented May 21, 2024

Added docs PR

@frenck frenck added this to the 2024.6.0b0 milestone May 23, 2024
Copy link
Contributor

@edenhaus edenhaus left a comment

Choose a reason for hiding this comment

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

Thanks @frenck 👍

@edenhaus edenhaus merged commit 9224997 into dev May 24, 2024
38 checks passed
@edenhaus edenhaus deleted the frenck-2024-0340 branch May 24, 2024 07:34
@github-actions github-actions bot locked and limited conversation to collaborators May 25, 2024
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.

None yet

2 participants