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

Question: how to listen to several events of the same type #151

Closed
wsw70 opened this issue Feb 8, 2021 · 3 comments
Closed

Question: how to listen to several events of the same type #151

wsw70 opened this issue Feb 8, 2021 · 3 comments

Comments

@wsw70
Copy link
Contributor

wsw70 commented Feb 8, 2021

The documentation states

A single function can have any or all of the decorator types specified, but at most one of each type.

In such a case how can I monitor several events of the same type (say - two MQTT topics, or several actions)?

My current solution is to have intermediate functions, each having one decorator, and both calling the actual function that handles the event - but there may be a better solution?

@dlashua
Copy link
Contributor

dlashua commented Feb 8, 2021

That's how I do it too: a function to do the work, and multiple functions with an event_trigger decorator on it that just calls the first function.

@craigbarratt
Copy link
Member

For @state_trigger and @time_trigger you can specify multiple arguments (or lists of arguments), so a single function can be triggered by multiple state expressions or time specifications.

For @event_trigger and @mqtt_trigger you can currently only specify a single event or mqtt topic, although mqtt supports wildcards, so one trigger can capture multiple topics if they have similar names that can be matched by a wildcard.

@event_trigger could be extended to support multiple event names if there is interest. In the meantime, @dlashua's solution is the best one in the few cases where a common handler function for different events is needed.

@Beiri22
Copy link

Beiri22 commented Feb 9, 2021

For @state_trigger and @time_trigger you can specify multiple arguments (or lists of arguments), so a single function can be triggered by multiple state expressions or time specifications.

Please see #157

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

No branches or pull requests

4 participants