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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate optional script context #39034

Merged
merged 4 commits into from Aug 21, 2020
Merged

Conversation

balloob
Copy link
Member

@balloob balloob commented Aug 19, 2020

Breaking change

Custom components: It is deprecated to not pass a context to script.async_run(). This will now print a warning. If you're inside an entity, use self._context.

Proposed change

This makes it mandatory to pass a context to script.async_run. If not passed in, it will print a warning so custom integrations get time to adapt.

Context will now also be available as one of the variables inside a script. This will make it easy to see if a state has been last changed by the script itself.

  • Turn on light
  • Wait 10 minutes
  • If light last state was done by this script, turn off

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 configuration.yaml

Additional information

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

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:

@probot-home-assistant
Copy link

Hey there @PhracturedBlue, @tetienne, mind taking a look at this pull request as its been labeled with an integration (template) you are listed as a codeowner for? Thanks!
(message by CodeOwnersMention)

@probot-home-assistant
Copy link

Hey there @joogps, mind taking a look at this pull request as its been labeled with an integration (panasonic_viera) you are listed as a codeowner for? Thanks!
(message by CodeOwnersMention)

@balloob
Copy link
Member Author

balloob commented Aug 19, 2020

I was getting this test failure locally too but I don't really understand why. @pnbruckner do you maybe have a hint?

Copy link
Contributor

@pnbruckner pnbruckner left a comment

Choose a reason for hiding this comment

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

Some minor feedback.

Also, regarding the test that is failing (test_repeat_conditional in tests/helpers/test_script.py), although it hadn't failed for me, it does look like I left out one call to wait_started.clear(), specifically after line 922:

        for index in range(2, count + 1):
            await asyncio.wait_for(wait_started.wait(), 1)
            wait_started.clear()
            hass.states.async_set("sensor.test", "next")
            await asyncio.wait_for(wait_started.wait(), 1)
            wait_started.clear()
            hass.states.async_set("sensor.test", index)
        await asyncio.wait_for(wait_started.wait(), 1)
        wait_started.clear()                              # <==== add this line
        hass.states.async_set("sensor.test", "next")
        await asyncio.wait_for(wait_started.wait(), 1)
        wait_started.clear()
        hass.states.async_set("sensor.test", "done")
        await asyncio.wait_for(hass.async_block_till_done(), 1)

homeassistant/components/panasonic_viera/media_player.py Outdated Show resolved Hide resolved
homeassistant/helpers/script.py Outdated Show resolved Hide resolved
Dev automation moved this from Needs review to Review in progress Aug 19, 2020
Dev automation moved this from Review in progress to Reviewer approved Aug 20, 2020
@balloob balloob force-pushed the deprecate-optional-script-context branch from e497e03 to 0417a3a Compare August 21, 2020 11:46
@balloob balloob merged commit 05d54a6 into dev Aug 21, 2020
Dev automation moved this from Reviewer approved to Done Aug 21, 2020
@balloob balloob deleted the deprecate-optional-script-context branch August 21, 2020 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Dev
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants