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

Add config reloaded events for automation and scene #34664

Merged
merged 3 commits into from Jun 1, 2020
Merged

Conversation

frenck
Copy link
Member

@frenck frenck commented Apr 24, 2020

Proposed change

This PR is adding events when automations or scenes might have been reloaded (and thus might have been changed).

Reasoning and use case:

Automations (and others) can be changed on the fly. Either via UI editing, UI reloading or by reloading YAML configuration via, e.g., the automation.reload service.

Triggers fire, conditions are checked and actions follow. The beautify of this is that automations can be used to bring your home into a state automatically.

Consider this automation:

alias: garden_lights_on
trigger:
  - platform: homeassistant
    event: start
  - platform: state
    entity_id:
      - alarm_control_panel.home_alarm
      - sun.sun
condition:
  - condition: state
    entity_id: alarm_control_panel.home_alarm
    state: disarmed
  - condition: numeric_state
    entity_id: sun.sun
    value_template: >-
      {{ state_attr('sun.sun', 'elevation') }}
    below: 1.0
action:
  - service: light.turn_on
    data:
      entity_id:
        - light.garden_wall
      transition: 5

The Home Assistant start is used here to ensure the state of the light is correct if Home Assistant starts (nb: Due to recent changes, that is not as viable anymore... but not the point 馃槈).

This is nice and all, but if automation gets changed, we need a manual trigger or re-apply manually, instead of it just happing (if automation is set up that way).

The same can be done for e.g., a scene. If a scene changes, the automation can re-trigger applying the changed/updated scene.

trigger:
  - platform: event
    event: automation_reloaded

With the change in the PR, is becomes possible for an automation to listen for the updated event, after which it can trigger and re-evaluate conditions and/or re-apply changes in the automation automatically.

This PR only applies to scenes and automations. In all other cases, it will cause entities to fire a change on entity level, which will just work as we are used to.

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

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

@probot-home-assistant
Copy link

Hey there @home-assistant/core, mind taking a look at this pull request as its been labeled with a integration (automation) you are listed as a codeowner for? Thanks!

@project-bot project-bot bot added this to Needs review in Dev Apr 24, 2020
@MartinHjelmare MartinHjelmare moved this from Needs review to Incoming in Dev Apr 26, 2020
@frenck frenck changed the title Add automation reloaded event Add updated events for internal integration supporting reloading Apr 26, 2020
@frenck frenck changed the title Add updated events for internal integration supporting reloading Add config updated events for internal integrations Apr 26, 2020
@frenck frenck changed the title Add config updated events for internal integrations Add config reloaded events for automation and scene Jun 1, 2020
@frenck frenck marked this pull request as ready for review June 1, 2020 19:57
@frenck
Copy link
Member Author

frenck commented Jun 1, 2020

Stripped down this PR to its bare basics, limiting its scope, rebased it, and added documentation.

homeassistant/const.py Outdated Show resolved Hide resolved
Dev automation moved this from Incoming to Reviewer approved Jun 1, 2020
@frenck
Copy link
Member Author

frenck commented Jun 1, 2020

It looks like an unrelated test failure to me.

@balloob
Copy link
Member

balloob commented Jun 1, 2020

That's unrelated indeed. That's flakiness caused by the background PR.

@balloob balloob merged commit 1883b1d into dev Jun 1, 2020
Dev automation moved this from Reviewer approved to Done Jun 1, 2020
@balloob balloob deleted the frenck-2020-0436 branch June 1, 2020 22:19
@balloob balloob mentioned this pull request Jun 1, 2020
20 tasks
@balloob
Copy link
Member

balloob commented Jun 1, 2020

Fix for the flaky test #36358

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

3 participants