Class Rules

java.lang.Object
org.openhab.core.model.script.lib.Rules

@NonNullByDefault public class Rules extends Object
Rules provides DSL access to rule operations.
Author:
Ravi Nadahar - Initial contribution
  • Constructor Details

    • Rules

      public Rules()
  • Method Details

    • getRule

      public static @Nullable Rule getRule(String ruleUid)
      Get a rule by UID.
      Parameters:
      ruleUid -
      Returns:
      The Rule or null if no matching rule exists.
    • runRule

      public static Map<String,@Nullable Object> runRule(String ruleUid)
      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 no RuleManager instance exists.
    • runRule

      public static Map<String,@Nullable Object> runRule(String ruleUid, boolean considerConditions)
      Run the rule with the specified UID while optionally taking conditions into account.
      Parameters:
      ruleUid - the UID of the rule to run.
      considerConditions - true to 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 no RuleManager instance 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 - the Map of String and Object pairs 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 no RuleManager instance 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 - true to not run the rule if its conditions don't qualify.
      context - the pairs of Strings and Objects 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 no RuleManager instance 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 - true to not run the rule if its conditions don't qualify.
      context - the Map of String and Object pairs 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 no RuleManager instance exists.
    • isRuleEnabled

      public static boolean isRuleEnabled(String ruleUid)
      Check whether the specified rule is enabled.
      Parameters:
      ruleUid - the UID of the rule to check.
      Returns:
      true if the rule is enabled, false otherwise.
      Throws:
      IllegalArgumentException - If a rule with the specified UID doesn't exist.
      IllegalStateException - If no RuleManager instance exists.
    • setRuleEnabled

      public static void setRuleEnabled(String ruleUid, boolean enabled)
      Set whether the specified rule is enabled.
      Parameters:
      ruleUid - the UID of the rule to enable or disable.
      enabled - true to enable the rule, false to disable the rule.
      Throws:
      IllegalArgumentException - If a rule with the specified UID doesn't exist.
      IllegalStateException - If no RuleManager instance exists.
    • getRuleManager

      public static @Nullable RuleManager getRuleManager()
      Returns:
      The RuleManager or null.