Skip to content

Add support for "alias" in script steps device, device_condition, and conditions#46647

Merged
balloob merged 9 commits intohome-assistant:devfrom
emontnemery:actions_conditions_alias
Feb 21, 2021
Merged

Add support for "alias" in script steps device, device_condition, and conditions#46647
balloob merged 9 commits intohome-assistant:devfrom
emontnemery:actions_conditions_alias

Conversation

@emontnemery
Copy link
Contributor

@emontnemery emontnemery commented Feb 16, 2021

Proposed change

See: WTH can’t we annotate sequence steps for logging?.

The backend already has the alias field to mostly achieve this WTH. But alias is not supported for all action steps.

This PR:

  • Adds alias to the following action step type schemas:
    • device
    • scene
    • alias for choose choices
  • Adds alias to all conditions -- "numeric_state", "state", "sun", etc..
  • Consolidates duplicate calls to self._log("Executing step ... into a common method

This is #40772 by @donkawechico, with updated tests.

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)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example entry for configuration.yaml:

# Example script.yaml
test_alias:
  alias: Test Alias
  sequence:
  - type: turn_off
    device_id: 401d32d1bfd440f0b887f02d2b8d5c66
    entity_id: light.chandelier
    domain: light
    alias: TURN OFF CHANDELIER
  - condition: state
    entity_id: light.chandelier
    state: 'off'
    alias: LEAVE SCRIPT IF CHANDELIER DIDNT TURN ON
  - scene: scene.warm
    alias: ACTUALLY FORGET THE CHANDELIER JUST MAKE IT NICE
  mode: single
  # ...

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
  • The code has been formatted using Black (black --fast 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.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

@donkawechico
Copy link
Contributor

donkawechico commented Feb 16, 2021

I think I already have a PR up that does this. On my phone right now but will try to find in a few minutes.

EDIT: Ha, nevermind. I see your note now that this IS my PR, just updated with better tests :P Didn't see that when I skimmed on my phone. Carry on, and thanks!

@emontnemery
Copy link
Contributor Author

@donkawechico that's right, your PR was great, I'm just adding some tests. Do you have any suggestion for how to verify the condition aliases? They're currently not used for anything, unlike the action aliases which are used for logging.

@donkawechico
Copy link
Contributor

donkawechico commented Feb 17, 2021

@donkawechico that's right, your PR was great, I'm just adding some tests. Do you have any suggestion for how to verify the condition aliases? They're currently not used for anything, unlike the action aliases which are used for logging.

@emontnemery By "how to verify the condition aliases" do you mean "how to write unit tests for conditional schemas"? Or do you mean how to verify that this PR successfully adds support for aliases in conditionals.

If you mean unit tests, I remember having some difficulty figuring out how to write a unit test against conditional schemas. I forget what the difficulty was though.

If you mean verifying the change, then I think all you have to do is find a script/automation that uses a conditional step and try adding an alias: key to it. If your configuration check passes (e.g. hass --script check_config) then it works!

msg, *args, level=level, **kwargs
)

def _step_log(self, default_message, delay=None):
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't delay be called timeout, as it's how long we're going to wait for something ?

Copy link
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

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

Looks good! One comment.

@balloob balloob merged commit 2d70806 into home-assistant:dev Feb 21, 2021
@frenck
Copy link
Member

frenck commented Feb 21, 2021

We should make sure the documentation for this is updated

@github-actions github-actions bot locked and limited conversation to collaborators Feb 22, 2021
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.

5 participants