Class Rules
java.lang.Object
org.openhab.core.model.script.lib.Rules
Rules provides DSL access to rule operations.- Author:
- Ravi Nadahar - Initial contribution
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable RuleGet a rule by UID.static @Nullable RuleManagerstatic booleanisRuleEnabled(String ruleUid) Check whether the specified rule is enabled.Run the rule with the specified UID.Run the rule with the specified UID while optionally taking conditions into account.Run the rule with the specified UID with the specified context, while optionally taking conditions into account.Run the rule with the specified UID with the specified context, while optionally taking conditions into account.Run the rule with the specified UID with the specified context.static voidsetRuleEnabled(String ruleUid, boolean enabled) Set whether the specified rule is enabled.
-
Constructor Details
-
Rules
public Rules()
-
-
Method Details
-
getRule
Get a rule by UID.- Parameters:
ruleUid-- Returns:
- The
Ruleornullif no matching rule exists.
-
runRule
Run the rule with the specified UID.- Parameters:
ruleUid- the UID of the rule to run.- Returns:
- A copy of the rule context, including possible return values.
- Throws:
IllegalArgumentException- If a rule with the specified UID doesn't exist.IllegalStateException- If noRuleManagerinstance exists.
-
runRule
Run the rule with the specified UID while optionally taking conditions into account.- Parameters:
ruleUid- the UID of the rule to run.considerConditions-trueto not run the rule if its conditions don't qualify.- Returns:
- A copy of the rule context, including possible return values.
- Throws:
IllegalArgumentException- If a rule with the specified UID doesn't exist.IllegalStateException- If noRuleManagerinstance exists.
-
runRule
public static Map<String,@Nullable Object> runRule(String ruleUid, Map<String, @Nullable Object> context) Run the rule with the specified UID with the specified context.- Parameters:
ruleUid- the UID of the rule to run.context- theMapofStringandObjectpairs that constitutes the context.- Returns:
- A copy of the rule context, including possible return values.
- Throws:
IllegalArgumentException- If a rule with the specified UID doesn't exist.IllegalStateException- If noRuleManagerinstance exists.
-
runRule
public static Map<String,@Nullable Object> runRule(String ruleUid, boolean considerConditions, Object... context) Run the rule with the specified UID with the specified context, while optionally taking conditions into account.- Parameters:
ruleUid- the UID of the rule to run.considerConditions-trueto not run the rule if its conditions don't qualify.context- the pairs ofStrings andObjects that constitutes the context. Must be in pairs, the first is the key, the second is the value.- Returns:
- A copy of the rule context, including possible return values.
- Throws:
IllegalArgumentException- If a rule with the specified UID doesn't exist.IllegalStateException- If noRuleManagerinstance exists.
-
runRule
public static Map<String,@Nullable Object> runRule(String ruleUid, boolean considerConditions, @Nullable Map<String, @Nullable Object> context) Run the rule with the specified UID with the specified context, while optionally taking conditions into account.- Parameters:
ruleUid- the UID of the rule to run.considerConditions-trueto not run the rule if its conditions don't qualify.context- theMapofStringandObjectpairs that constitutes the context.- Returns:
- A copy of the rule context, including possible return values.
- Throws:
IllegalArgumentException- If a rule with the specified UID doesn't exist.IllegalStateException- If noRuleManagerinstance exists.
-
isRuleEnabled
Check whether the specified rule is enabled.- Parameters:
ruleUid- the UID of the rule to check.- Returns:
trueif the rule is enabled,falseotherwise.- Throws:
IllegalArgumentException- If a rule with the specified UID doesn't exist.IllegalStateException- If noRuleManagerinstance exists.
-
setRuleEnabled
Set whether the specified rule is enabled.- Parameters:
ruleUid- the UID of the rule to enable or disable.enabled-trueto enable the rule,falseto disable the rule.- Throws:
IllegalArgumentException- If a rule with the specified UID doesn't exist.IllegalStateException- If noRuleManagerinstance exists.
-
getRuleManager
- Returns:
- The
RuleManagerornull.
-