core.rules¶
The rules module contains some utility functions and a decorator that can:
decorate a Jython class to create a
SimpleRule
,decorate the
when
function decorator to create aSimpleRule
.
-
core.rules.
rule
(name=None, description=None, tags=None)¶ This decorator can be used with both functions and classes to create rules.
See Decorators for a full description of how to use this decorator.
Examples
@rule('name', 'description', ['tag1', 'tag2']) @rule('name', tags=['tag1', 'tag2']) @rule('name')
- Parameters
name (str) – display name of the rule
description (str) – (optional) description of the rule
tags (list) – (optional) list of tags as strings
-
core.rules.
addRule
(rule)¶ This function adds a
rule
to openHAB’sruleRegistry
.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.- Parameters
rule (SimpleRule) – a rule to add to openHAB
- Returns
the Rule object that was created
- Return type
Rule
-
core.rules.
set_uid_prefix
(rule, prefix=None)¶ This function changes the UID of a rule, with the option to include a specified text.
Warning
This function needs some attention in order to work with the Automation API changes included in S1319.
- Parameters
rule (Rule) – the rule to modify
prefix (str) – (optional) the text to include in the UID