Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Commit

Permalink
make module builders available in scripted rules
Browse files Browse the repository at this point in the history
Signed-off-by: Kai Kreuzer <kai@openhab.org>
  • Loading branch information
kaikreuzer committed Jul 24, 2018
1 parent 36a470b commit 409cc13
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
Expand Up @@ -26,6 +26,10 @@
import org.eclipse.smarthome.automation.RuleRegistry;
import org.eclipse.smarthome.automation.Trigger;
import org.eclipse.smarthome.automation.Visibility;
import org.eclipse.smarthome.automation.core.util.ActionBuilder;
import org.eclipse.smarthome.automation.core.util.ConditionBuilder;
import org.eclipse.smarthome.automation.core.util.ModuleBuilder;
import org.eclipse.smarthome.automation.core.util.TriggerBuilder;
import org.eclipse.smarthome.automation.module.script.ScriptExtensionProvider;
import org.eclipse.smarthome.automation.module.script.rulesupport.shared.RuleSupportRuleRegistryDelegate;
import org.eclipse.smarthome.automation.module.script.rulesupport.shared.ScriptedAutomationManager;
Expand Down Expand Up @@ -76,6 +80,11 @@ public class RuleSupportScriptExtension implements ScriptExtensionProvider {
staticTypes.put("ConditionHandlerFactory", ScriptedConditionHandlerFactory.class);
staticTypes.put("TriggerHandlerFactory", ScriptedTriggerHandlerFactory.class);

staticTypes.put("ModuleBuilder", ModuleBuilder.class);
staticTypes.put("ActionBuilder", ActionBuilder.class);
staticTypes.put("ConditionBuilder", ConditionBuilder.class);
staticTypes.put("TriggerBuilder", TriggerBuilder.class);

staticTypes.put("Configuration", Configuration.class);
staticTypes.put("Action", Action.class);
staticTypes.put("Condition", Condition.class);
Expand All @@ -92,7 +101,8 @@ public class RuleSupportScriptExtension implements ScriptExtensionProvider {
types.add(AUTOMATION_MANAGER);
types.add(RULE_REGISTRY);

presets.put(RULE_SUPPORT, Arrays.asList("Configuration", "Action", "Condition", "Trigger", "Rule"));
presets.put(RULE_SUPPORT, Arrays.asList("Configuration", "Action", "Condition", "Trigger", "Rule",
"ModuleBuilder", "ActionBuilder", "ConditionBuilder", "TriggerBuilder"));
presets.put("RuleSimple", Arrays.asList("SimpleActionHandler", "SimpleConditionHandler", "SimpleTriggerHandler",
"SimpleRule", "TriggerType", "ConfigDescriptionParameter", "ModuleType", "ActionType", "Visibility"));
presets.put("RuleFactories",
Expand Down
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.smarthome.automation.Condition;
import org.eclipse.smarthome.automation.Rule;
import org.eclipse.smarthome.automation.Trigger;
import org.eclipse.smarthome.automation.core.util.ActionBuilder;
import org.eclipse.smarthome.automation.core.util.ModuleBuilder;
import org.eclipse.smarthome.automation.core.util.RuleBuilder;
import org.eclipse.smarthome.automation.module.script.rulesupport.internal.ScriptedCustomModuleHandlerFactory;
Expand Down Expand Up @@ -164,7 +165,7 @@ public Rule addRule(Rule element) {
String privId = addPrivateActionHandler(
new SimpleRuleActionHandlerDelegate((SimpleRuleActionHandler) element));

Action scriptedAction = ModuleBuilder.createAction().withId(Integer.toString(moduleIndex++))
Action scriptedAction = ActionBuilder.create().withId(Integer.toString(moduleIndex++))
.withTypeUID("jsr223.ScriptedAction").withConfiguration(new Configuration()).build();
scriptedAction.getConfiguration().put("privId", privId);
actions.add(scriptedAction);
Expand Down
Expand Up @@ -181,7 +181,7 @@ public void setConfigurationDescriptions(@Nullable List<ConfigDescriptionParamet

@Override
public List<Condition> getConditions() {
return conditions;
return conditions == null ? new ArrayList<>() : conditions;
}

/**
Expand All @@ -190,17 +190,17 @@ public List<Condition> getConditions() {
* @param conditions a list with the conditions that should belong to this {@link Rule}.
*/
public void setConditions(@Nullable List<Condition> conditions) {
this.conditions = conditions == null ? new ArrayList<>() : conditions;
this.conditions = conditions;
}

@Override
public List<Action> getActions() {
return actions;
return actions == null ? new ArrayList<>() : actions;
}

@Override
public List<Trigger> getTriggers() {
return triggers;
return triggers == null ? new ArrayList<>() : triggers;
}

/**
Expand All @@ -209,7 +209,7 @@ public List<Trigger> getTriggers() {
* @param actions a list with the actions that should belong to this {@link Rule}.
*/
public void setActions(@Nullable List<Action> actions) {
this.actions = actions == null ? new ArrayList<>() : actions;
this.actions = actions;
}

/**
Expand All @@ -218,7 +218,7 @@ public void setActions(@Nullable List<Action> actions) {
* @param triggers a list with the triggers that should belong to this {@link Rule}.
*/
public void setTriggers(@Nullable List<Trigger> triggers) {
this.triggers = triggers == null ? new ArrayList<>() : triggers;
this.triggers = triggers;
}

/**
Expand Down

0 comments on commit 409cc13

Please sign in to comment.