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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix KNX telegram device trigger not firing after integration reload #107388

Merged
merged 1 commit into from
Jan 7, 2024

Conversation

farmio
Copy link
Contributor

@farmio farmio commented Jan 6, 2024

Proposed change

Previously the custom device trigger was not working after an integration reload since its callback HassJob was removed with the integration. (in

self._jobs.append(job)
)

Now it is loosely coupled with async_dispatcher_connect in the device triggers async_attach_trigger and
async_dispatcher_send which just happens for every telegram. So reloads don't affect this anymore.

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

home-assistant bot commented Jan 6, 2024

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

Code owner commands

Code owners of knx 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 knx 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.

@farmio farmio added this to the 2024.1.3 milestone Jan 6, 2024
@@ -99,6 +99,8 @@ def async_call_trigger_action(telegram: TelegramDict) -> None:
{"trigger": {**trigger_data, **telegram}},
)

return knx.telegrams.async_listen_telegram(
async_call_trigger_action, name="KNX device trigger call"
return async_dispatcher_connect(
Copy link
Member

Choose a reason for hiding this comment

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

Side note: Every device trigger needs to be based off a regular trigger like an event or integration specific trigger. Device triggers are just a device abstraction over a regular trigger and are not allowed to be standalone. I don't see any integration specific triggers in the KNX integration. See eg webostv integration for how to create an integration specific trigger.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, Knx doesn't have any integration specific triggers. This was never mentioned in a review, nor could I find anything about that in the developer documentations. I'll try to have a look into in when I have some time left. Are these always looked up in a <integration>/trigger.py file?

Until then, I think this bugfix should still be merged as it doesn't change any behaviour on the current device trigger except fixing integration reloads.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, the module should be named trigger.py.

My comment is a side note for the future.

Copy link
Member

Choose a reason for hiding this comment

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

It says here that device automations are built on top of core concepts and are not exposing new functionality.

Device Automations provide users with a device-centric layer on top of the core concepts of Home Assistant.

Device automations are not exposing extra functionality but are a way for users to not have to learn new concepts.

https://developers.home-assistant.io/docs/device_automation_index

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah thanks. So I can add a trigger like knx.telegram? That would be awesome.

I initially implemented this to avoid using HA events for the same effect, to not spam the event bus (and db) with unneeded Knx telegram information (~1-5 average, max 50 per second). I guess I can filter the integration specific trigger the same way we are doing for the device trigger, so this should be fine. (And not require any yaml as events would 😬)

Copy link
Member

Choose a reason for hiding this comment

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

Triggers are always available to be setup in automations via YAML if the user so wishes. Maybe that's not what you mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or right, that's not what I mean. We currently have Events, but users would need to configure address filters in yaml for it to work (to not spam).
With a trigger I think we could provide a form (/yaml) directly in the automation builder for this

@farmio farmio added the smash Indicator this PR is close to finish for merging or closing label Jan 7, 2024
Copy link
Contributor

@marvin-w marvin-w left a comment

Choose a reason for hiding this comment

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

Nice! Looks good to me!

@marvin-w marvin-w merged commit a9b51f0 into dev Jan 7, 2024
23 checks passed
@marvin-w marvin-w deleted the knx-device-trigger-reattach branch January 7, 2024 19:32
@github-actions github-actions bot locked and limited conversation to collaborators Jan 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bugfix by-code-owner cherry-picked cla-signed has-tests integration: knx Quality Scale: platinum 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.

KNX Device trigger - Telegram sent or received not working after reload of knx integration or restart
4 participants