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

Modify TelegramQueue.Callback filter from HA service #535

Merged
merged 2 commits into from
Jan 7, 2021

Conversation

farmio
Copy link
Member

@farmio farmio commented Dec 16, 2020

Description

  • knx_event: renamed fire_event_filter to event_filter and deprecated fire_event config option. A callback is now always registered for HA to be able to modify its group_addresses filter from a service.
  • added knx.event_register service allowing to add and remove group addresses to trigger knx_event without having to change configuration.
  • TelegramQueue.Callback: add group_addresses attribute to store a list of GroupAddress triggering the callback (additionally to address_filters).

So now the yaml configured filters live in Callback.address_filters and the group_addresses added by knx.event_register live in Callback.group_addresses.

With this it is possible to build automations using knx_event on the fly without changing or even reloading configuration.
So an HA automation could listen to automation_reloaded

automation:
  trigger:
    platform: event
    event_type: automation_reloaded
  action:
    service: knx.event_register
    data:
      address: "1/2/3"

to setup a group address listener for itself and later on use the registered knx_event. I think this could come in handy with blueprints.

This fits nicely to #497

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • I have performed a self-review of my own code
  • The documentation has been adjusted accordingly
  • The changes generate no new warnings
  • Tests have been added that prove the fix is effective or that the feature works
  • The changes are documented in the changelog
  • The Homeassistant plugin has been adjusted in case of new config options

@farmio farmio requested a review from marvin-w December 16, 2020 14:11
@coveralls
Copy link

coveralls commented Dec 16, 2020

Coverage Status

Coverage increased (+0.005%) to 94.877% when pulling 7ee9768 on farmio:dynamic_knx_event into 4379417 on XKNX:master.

@farmio farmio mentioned this pull request Dec 16, 2020
10 tasks
@farmio
Copy link
Member Author

farmio commented Dec 16, 2020

🤔 It strikes me that it is not possible to use multiple trigger-action blocks in one automation. Who knew?
Well, maybe this will get changed in the future, I think the service can be useful nevertheless - even if only for testing purposes.

OK so now I think this is totally possible using choose in the action: block and trigger.platform or trigger.event in its condition. 🚀

):
"""Initialize Callback class."""
self.callback = callback
self.address_filters = address_filters
self._match_all = address_filters is None and group_addresses is None
Copy link
Member Author

Choose a reason for hiding this comment

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

This is kind of hacky 😬
I guess if Callback is instantiated with no filters (not even empty Lists) its not meant to be changed.
I'm open for suggestions 😉

@farmio farmio force-pushed the dynamic_knx_event branch from 6413476 to 7ee9768 Compare January 6, 2021 21:23
@farmio farmio merged commit b7c7427 into XKNX:master Jan 7, 2021
@farmio farmio deleted the dynamic_knx_event branch January 7, 2021 20:38
@farmio farmio mentioned this pull request Jan 15, 2021
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants