Class RuleExtensions

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

@NonNullByDefault public class RuleExtensions extends Object
RuleExtensions provides DSL Rule extensions.
Author:
Ravi Nadahar - Initial contribution
  • Constructor Details

    • RuleExtensions

      public RuleExtensions()
  • Method Details

    • run

      public static Map<String,@Nullable Object> run(Rule rule)
      Run the specified rule.
      Parameters:
      rule - the Rule to run.
      Returns:
      A copy of the rule context, including possible return values.
      Throws:
      IllegalArgumentException - If the specified rule isn't registered.
      IllegalStateException - If no RuleManager instance exists.
    • run

      public static Map<String,@Nullable Object> run(Rule rule, boolean considerConditions)
      Run the specified rule while optionally taking conditions into account.
      Parameters:
      rule - 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 the specified rule isn't registered.
      IllegalStateException - If no RuleManager instance exists.
    • run

      public static Map<String,@Nullable Object> run(Rule rule, Map<String,@Nullable Object> context)
      Run the specified rule with the specified context.
      Parameters:
      rule - 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 the specified rule isn't registered.
      IllegalStateException - If no RuleManager instance exists.
    • run

      public static Map<String,@Nullable Object> run(Rule rule, boolean considerConditions, Object... context)
      Run the specified rule with the specified context, while optionally taking conditions into account.
      Parameters:
      rule - 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 the specified rule isn't registered.
      IllegalStateException - If no RuleManager instance exists.
    • run

      public static Map<String,@Nullable Object> run(Rule rule, boolean considerConditions, @Nullable Map<String,@Nullable Object> context)
      Run the specified rule with the specified context, while optionally taking conditions into account.
      Parameters:
      rule - 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 the specified rule isn't registered.
      IllegalStateException - If no RuleManager instance exists.
    • isEnabled

      public static boolean isEnabled(Rule rule)
      Check whether the specified rule is enabled.
      Parameters:
      rule - the Rule to check.
      Returns:
      true if the rule is enabled, false otherwise.
      Throws:
      IllegalArgumentException - If the specified rule isn't registered.
      IllegalStateException - If no RuleManager instance exists.
    • setEnabled

      public static void setEnabled(Rule rule, boolean enabled)
      Set whether the specified rule is enabled.
      Parameters:
      rule - the Rule to enable or disable.
      enabled - true to enable the rule, false to disable the rule.
      Throws:
      IllegalArgumentException - If the specified rule isn't registered.
      IllegalStateException - If no RuleManager instance exists.