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
Attach logic trigger methods for plugins #106
Attach logic trigger methods for plugins #106
Conversation
…m parse_logic() # same behaviour as used in parse_item()
@@ -339,15 +339,18 @@ def _task(self, name, obj, by, source, dest, value): | |||
sh = self._sh # noqa | |||
try: | |||
exec(obj.bytecode) | |||
for method in logic.get_method_triggers(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this is a bug or a feature 😃 :
Due to the try/except Block starting in line 340, the hooked methods will only be called if the logic could be executed without error, and nobody called "exit()" inside the logic. In case of errors or "exit()" in the logic, the hooked methods will not be called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general it would be better to only trigger the methods when the logic was successfuly executed.
Using exit()
is IMHO a bad idea since it should only be used to completely exit the program. A logic is only a piece of code running inside SmartHome and should never use exit()
.
But if the others like to work around this and catching the exceptions before triggering the methods I can change this.
merged |
(copyied from mknx/smarthome#142)
Plugin developers have two possibilities to attach the logic to the SmartHome.py configuration / system:
parse_item()
methodparse_logic()
methodThe
parse_item()
method is called for each configured item and the plugin can decide if it is interested in item changes or not by simply returning an update method depending on the condition. When returning an update method a trigger method will be added to the item and invoked each time the item's value is changed.The
parse_logic()
method is called for each configured logic and the plugin can decide if it is interested in the logic or not. This can be used to setup some configuration for the plugin, but can't be used to register a trigger method which is invoked each time the logic is triggered. This patch add this functionality to register a trigger method for logics by simply returning a trigger method.Example:
This way a plugin can register a logic hook, which is called each time a logic was triggered.