Skip to content

Commit

Permalink
Added the rule UID as an attribute of the Action function
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Rushworth committed Nov 10, 2018
1 parent a43f72b commit 00a95b5
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions automation/lib/python/openhab/rules.py
Expand Up @@ -52,8 +52,9 @@ def init(self, *args, **kwargs):
return addRule(subclass())
else:
function = object
newRule = _FunctionRule(function, function.triggers, name=name, tags=tags)
get_automation_manager().addRule(newRule)
simpleRule = _FunctionRule(function, function.triggers, name=name, tags=tags)
newRule = get_automation_manager().addRule(simpleRule)
function.UID = newRule.UID
function.triggers = None
return function
return rule_decorator
Expand Down

1 comment on commit 00a95b5

@ScottKinSF
Copy link
Contributor

@ScottKinSF ScottKinSF commented on 00a95b5 Nov 10, 2018

Choose a reason for hiding this comment

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

@openhab-5iver , Looks good to me, thanks for asking me to review. I think there may be an issue in the assignment on line 57, shouldn't the UID of the new rule be accessed using getUID()?

https://github.com/eclipse/smarthome/blob/master/bundles/automation/org.eclipse.smarthome.automation.api/src/main/java/org/eclipse/smarthome/automation/Rule.java#L54

My only other comment is that in my local copy of rules.py, I changed the name of the function variable to callable_obj in order to make it clear (to me, anyway) that the object being decorated may be any callable object, not just a function or a class. In my uses of the rule decorator, I decorate callable instances of a class, not a function or a class. Excerpt from my local copy of rules.py:

            callable_obj = object
            newRule = _FunctionRule(callable_obj, callable_obj.triggers, name=name)
            addRule(newRule)
            callable_obj.triggers = None
            return callable_obj

Please sign in to comment.