8000 Simplify MQTT device triggers in automations by jbouwh · Pull Request #108309 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Simplify MQTT device triggers in automations #108309

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

Merged
merged 19 commits into from
Jan 30, 2024

Conversation

jbouwh
Copy link
Contributor
@jbouwh jbouwh commented Jan 18, 2024

Proposed change

When MQTT device triggers are used in an automation the discovery_id is no longer needed to identify an MQTT device trigger. Instead of the discovery_id identifier, that is based based on the config topic, now the device_id, type and subtype are used together as unique identifier. If the discovery_id is found in the MQTT device trigger automation config, then the discovery_id still will be used to identify the trigger instead, and the automation will keep working, even when the trigger has updated type or subtype, because existing triggers then will still be referenced by discovery_id.

For new automation's an MQTT device trigger, set up from the UR will not have discovery_id added any more, as the use of this parameter is deprecated now. A consequence of that is that device triggers cannot update type and subtype anymore without breaking the automation, which is no longer linked to the discovery_id.

No deprecation warnings for the use of discovery_id are being given at this time, and users will only see the difference in YAML, not in the UI.

Documentation

As this functionality is handled in the UI there is no specific documentation on how to add the MQTT trigger to a device automation in YAML. The change is not breaking because the documentation already has the following remark:

Also note that the combination of type and subtype should be unique for a device.

Background

The reason to change this because it makes it possible to create a blueprint based on the device_id, type and subtype without the need to add a discovery_id.

This PR is an alternative approach for PR #107830.

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:

@home-assistant
Copy link

Hey there @emontnemery, mind taking a look at this pull request as it has been labeled with an integration (mqtt) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of mqtt can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign mqtt Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@jbouwh jbouwh marked this pull request as draft January 19, 2024 11:28
@jbouwh jbouwh marked this pull request as ready for review January 19, 2024 12:24
@jbouwh jbouwh force-pushed the jbouwh-simplify-mqtt-device_trigger branch from 600074e to c637380 Compare January 19, 2024 22:09
@home-assistant home-assistant bot marked this pull request as draft January 22, 2024 08:33
@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@jbouwh jbouwh changed the title Simplify MQTT device triggers Simplify MQTT device triggers in automations Jan 22, 2024
@jbouwh jbouwh marked this pull request as ready for review January 22, 2024 16:58
@home-assistant home-assistant bot requested a review from emontnemery January 22, 2024 16:58
@jbouwh jbouwh requested a review from emontnemery January 24, 2024 08:36
Copy link
Contributor
@emontnemery emontnemery left a comment

Choose a reason for hiding this comment

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

Thanks @jbouwh 👍

@frenck frenck added the smash Indicator this PR is close to finish for merging or closing label Jan 30, 2024
jbouwh and others added 2 commits January 30, 2024 15:28
Co-authored-by: Erik Montnemery <erik@montnemery.com>
Co-authored-by: Erik Montnemery <erik@montnemery.com>
@jbouwh jbouwh merged commit 04f0128 into dev Jan 30, 2024
@jbouwh jbouwh deleted the jbouwh-simplify-mqtt-device_trigger branch January 30, 2024 19:50
@github-actions github-actions bot locked and limited conversation to collaborators Jan 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
by-code-owner cla-signed code-quality has-tests integration: mqtt Quality Scale: gold small-pr PRs with less than 30 lines. smash Indicator this PR is close to finish for merging or closing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mqtt device trigger -> discovery_id does not work with trigger_variables?
4 participants
0