Пример #1
0
 def rule_decorator(object):
     if isclass(object):
         clazz = object
         def init(self, *args, **kwargs):
             scope.SimpleRule.__init__(self)
             if name is None:
                 if hasattr(clazz, '__name__'):
                     self.name = clazz.__name__
                 else:
                     self.name = "JSR223-Jython"
             else:
                 self.name = name
             #set_uid_prefix(self)
             self.log = logging.getLogger(LOG_PREFIX + "." + self.name)
             clazz.__init__(self, *args, **kwargs)
             if description is not None:
                 self.description = description
             elif self.description is None and clazz.__doc__:
                 self.description = clazz.__doc__
             if hasattr(self, "getEventTriggers"):
                 self.triggers = log_traceback(self.getEventTriggers)()
             if tags is not None:
                 self.tags = set(tags)
         subclass = type(clazz.__name__, (clazz, scope.SimpleRule), dict(__init__=init))
         subclass.execute = log_traceback(clazz.execute)
         return addRule(subclass())
     else:
         function = object
         newRule = _FunctionRule(function, function.triggers, name=name, description=description, tags=tags)
         get_automation_manager().addRule(newRule)
         function.triggers = None
         return function
Пример #2
0
def addRule(rule):
    """Adds ``rule`` to openHAB's ``ruleRegistry``.

    This is a wrapper of ``automationManager.addRule()`` that does not require
    any additional imports. The `addRule` function is similar to the 
    `automationManager.addRule` function, except that it can be safely used in
    modules (versus scripts). Since the `automationManager` is different for
    every script scope, the `core.rules.addRule` function looks up the
    automation manager for each call. See :ref:`Guides/Rules:Extensions` for
    examples of how to use this function.

    Args:
        rule (Rule): A rule to add to openHAB.
    """
    log.debug("Added rule [{}]".format(rule.name))
    return get_automation_manager().addRule(rule)
Пример #3
0
def addRule(new_rule):
    """
    This function adds a ``rule`` to openHAB's ``ruleRegistry``.

    This is a wrapper of ``automationManager.addRule()`` that does not require
    any additional imports. The `addRule` function is similar to the
    `automationManager.addRule` function, except that it can be safely used in
    modules (versus scripts). Since the `automationManager` is different for
    every script scope, the `core.rules.addRule` function looks up the
    automation manager for each call.

    Args:
        new_rule (SimpleRule): a rule to add to openHAB

    Returns:
        Rule: the Rule object that was created
    """
    LOG.debug(u"Added rule '{}'".format(new_rule.name))
    return get_automation_manager().addRule(new_rule)
Пример #4
0
def addRule(rule):
    get_automation_manager().addRule(rule)
Пример #5
0
def addRule(rule):
    logging.getLogger(LOG_PREFIX + ".core.rules").debug("Added rule [{}]".format(rule.name))
    return get_automation_manager().addRule(rule)