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 trigger service to template #48630

Closed
wants to merge 3 commits into from
Closed

Conversation

balloob
Copy link
Member

@balloob balloob commented Apr 2, 2021

Breaking change

Proposed change

Add a new service to manually trigger a trigger-based template entity with ability to pass variables.

Also fixes a bug for trigger-based entities without a unique ID Bug fix extracted to #48631

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:

@balloob
Copy link
Member Author

balloob commented Apr 2, 2021

Removed milestone and moving the bug fix to new PR.

@balloob balloob force-pushed the add-trigger-service-template branch from 0ad1e59 to 1eb3741 Compare April 2, 2021 17:25
@amelchio
Copy link
Contributor

amelchio commented Apr 3, 2021

As a user, it would be nice if this could be rolled into homeassistant.update_entity but I guess that is not so architecturally sound 馃

Could we at least support homeassistant.update_entity and just error out if the template accesses trigger data? I can see lots of situations where trigger entities will be used to avoid an automation, not using trigger data at all. It would then be nice to not have to remember which way to update.

@balloob
Copy link
Member Author

balloob commented Apr 3, 2021

Right now hitting homeassistant.update_entity for a trigger entity will do nothing. You think it should try to re-render and set itself to unavailable if rendering fails?

@balloob balloob force-pushed the add-trigger-service-template branch from 6bcd386 to caa365e Compare April 3, 2021 23:58
@amelchio
Copy link
Contributor

amelchio commented Apr 4, 2021

Actually, thinking about it a bit more, I am not quite sure what is being proposed here. Can you provide a use case?

It seems a bit odd for me to support variables in the forced trigger when those are not available to normal triggers but I guess you have something in mind?

You think it should try to re-render and set itself to unavailable if rendering fails?

I don't think it should set unavailable; that value is user controlled. Just treat trigger as an undefined variable.

@balloob
Copy link
Member Author

balloob commented Apr 5, 2021

Just like we pass variables to scripts, you would pass variables to the rendering method. It could be a way to have an automation conditionally update an entity.

@amelchio
Copy link
Contributor

amelchio commented Apr 5, 2021

Sure, I understand what the feature does ... just not when that would actually be needed. We shouldn't add features just because they are easy to implement, they should preferably be useful too ;-)

  1. Variables are supported if and only if the trigger is trigger: [] because the variables would not be set for any actual trigger, right? I wonder if this is such a big limitation that we are as well off without the variables support in a corner case.
  2. The template.trigger itself now seems dubious to me. When is it useful to trigger with synthetic trigger data? The same could be achieved by passing the data in a custom event (which would be fired in a script, so supports variables); is the use case frequent enough that special support is warranted?

So I guess that I am now suggesting to drop this PR entirely and instead support homeassistant.update_entity (which will fail for templates referencing trigger but that is okay).

@balloob balloob closed this Apr 13, 2021
Dev automation moved this from Needs review to Cancelled Apr 13, 2021
@balloob
Copy link
Member Author

balloob commented Apr 13, 2021

We can revisit in future

@github-actions github-actions bot locked and limited conversation to collaborators Apr 14, 2021
@pvizeli pvizeli deleted the add-trigger-service-template branch May 14, 2021 12:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Dev
  
Cancelled
Development

Successfully merging this pull request may close these issues.

None yet

3 participants