use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.
the class RuleTemplateRegistry method copyConditions.
private List<Condition> copyConditions(List<Condition> conditions) {
List<Condition> res = new ArrayList<Condition>(11);
if (conditions != null) {
for (Condition c : conditions) {
Configuration conf = new Configuration();
conf.setProperties(c.getConfiguration().getProperties());
Condition condition = new Condition(c.getId(), c.getTypeUID(), conf, new HashMap<String, String>(c.getInputs()));
condition.setLabel(c.getLabel());
condition.setDescription(c.getDescription());
res.add(condition);
}
}
return res;
}
use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.
the class ModuleTypeRegistryImpl method copyTriggers.
private static List<Trigger> copyTriggers(List<Trigger> triggers) {
List<Trigger> res = new ArrayList<Trigger>(11);
if (triggers != null) {
for (Trigger t : triggers) {
Configuration c = new Configuration();
c.setProperties(t.getConfiguration().getProperties());
Trigger trigger = new Trigger(t.getId(), t.getTypeUID(), c);
trigger.setLabel(trigger.getLabel());
trigger.setDescription(trigger.getDescription());
res.add(trigger);
}
}
return res;
}
use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.
the class RunRuleModuleTest method createSceneRule.
private Rule createSceneRule() {
final Configuration sceneRuleAction1Config = new Configuration(Collections.unmodifiableMap(Stream.of(new SimpleEntry<>("itemName", "switch1"), new SimpleEntry<>("command", "ON")).collect(Collectors.toMap((e) -> e.getKey(), (e) -> e.getValue()))));
final Configuration sceneRuleAction2Config = new Configuration(Collections.unmodifiableMap(Stream.of(new SimpleEntry<>("itemName", "switch2"), new SimpleEntry<>("command", "ON")).collect(Collectors.toMap((e) -> e.getKey(), (e) -> e.getValue()))));
final Configuration sceneRuleAction3Config = new Configuration(Collections.unmodifiableMap(Stream.of(new SimpleEntry<>("itemName", "switch3"), new SimpleEntry<>("command", "ON")).collect(Collectors.toMap((e) -> e.getKey(), (e) -> e.getValue()))));
final Rule sceneRule = new Rule("exampleSceneRule");
sceneRule.setActions(Arrays.asList(new Action[] { new Action("sceneItemPostCommandAction1", "core.ItemCommandAction", sceneRuleAction1Config, null), new Action("sceneItemPostCommandAction2", "core.ItemCommandAction", sceneRuleAction2Config, null), new Action("sceneItemPostCommandAction3", "core.ItemCommandAction", sceneRuleAction3Config, null) }));
sceneRule.setName("Example Scene");
return sceneRule;
}
use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.
the class RuntimeRuleTest method ruleEnableHandlerWorks.
@Test
@Ignore
public void ruleEnableHandlerWorks() throws ItemNotFoundException {
final RuleRegistry ruleRegistry = getService(RuleRegistry.class);
final String firstRuleUID = "FirstTestRule";
final String secondRuleUID = "SecondTestRule";
final String thirdRuleUID = "ThirdTestRule";
final String[] firstConfig = new String[] { "FirstTestRule", "SecondTestRule" };
final String[] secondConfig = new String[] { "FirstTestRule" };
final String firstRuleAction = "firstRuleAction";
final String secondRuleAction = "secondRuleAction";
try {
final Configuration triggerConfig = new Configuration(Stream.of(new SimpleEntry<>("itemName", "myMotionItem3")).collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue())));
final Configuration actionConfig = new Configuration(Stream.of(new SimpleEntry<>("enable", false), new SimpleEntry<>("ruleUIDs", firstConfig)).collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue())));
final Rule rule = new Rule(firstRuleAction);
rule.setTriggers(Arrays.asList(new Trigger[] { new Trigger("ItemStateChangeTrigger3", "core.ItemStateChangeTrigger", triggerConfig) }));
rule.setActions(Arrays.asList(new Action[] { new Action("RuleAction", "core.RuleEnablementAction", actionConfig, null) }));
ruleRegistry.add(new Rule(firstRuleUID));
ruleRegistry.add(new Rule(secondRuleUID));
ruleRegistry.add(new Rule(thirdRuleUID));
ruleRegistry.add(rule);
final ItemRegistry itemRegistry = getService(ItemRegistry.class);
final EventPublisher eventPublisher = getService(EventPublisher.class);
final Item myMotionItem = itemRegistry.getItem("myMotionItem3");
eventPublisher.post(ItemEventFactory.createCommandEvent("myMotionItem3", TypeParser.parseCommand(myMotionItem.getAcceptedCommandTypes(), "ON")));
waitForAssert(() -> {
Assert.assertEquals(RuleStatus.DISABLED, ruleRegistry.getStatus(firstRuleUID));
Assert.assertEquals(RuleStatus.DISABLED, ruleRegistry.getStatus(secondRuleUID));
Assert.assertEquals(RuleStatus.IDLE, ruleRegistry.getStatus(thirdRuleUID));
});
final Configuration triggerConfig2 = new Configuration(Stream.of(new SimpleEntry<>("itemName", "myMotionItem3")).collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue())));
final Configuration actionConfig2 = new Configuration(Stream.of(new SimpleEntry<>("enable", true), new SimpleEntry<>("ruleUIDs", secondConfig)).collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue())));
final Rule rule2 = new Rule(secondRuleAction);
rule2.setTriggers(Arrays.asList(new Trigger[] { new Trigger("ItemStateChangeTrigger3", "core.ItemStateChangeTrigger", triggerConfig2) }));
rule2.setActions(Arrays.asList(new Action[] { new Action("RuleAction", "core.RuleEnablementAction", actionConfig2, null) }));
ruleRegistry.add(rule2);
eventPublisher.post(ItemEventFactory.createCommandEvent("myMotionItem3", TypeParser.parseCommand(myMotionItem.getAcceptedCommandTypes(), "OFF")));
waitForAssert(() -> {
Assert.assertEquals(RuleStatus.IDLE, ruleRegistry.getStatus(firstRuleUID));
Assert.assertEquals(RuleStatus.DISABLED, ruleRegistry.getStatus(secondRuleUID));
Assert.assertEquals(RuleStatus.IDLE, ruleRegistry.getStatus(thirdRuleUID));
});
} finally {
ruleRegistry.remove(firstRuleUID);
ruleRegistry.remove(secondRuleUID);
ruleRegistry.remove(thirdRuleUID);
ruleRegistry.remove(firstRuleAction);
ruleRegistry.remove(secondRuleAction);
}
}
use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.
the class RuleUtils method getActionsCopy.
/**
* This method creates deep copy of list of actions
*
* @param actions list of actions
* @return deep copy of list of actions or empty list when the parameter is null.
*/
public static List<Action> getActionsCopy(List<Action> actions) {
List<Action> res = new ArrayList<Action>();
if (actions != null) {
for (Action a : actions) {
Action action = new Action(a.getId(), a.getTypeUID(), new Configuration(a.getConfiguration().getProperties()), new HashMap<String, String>(a.getInputs()));
action.setLabel(a.getLabel());
action.setDescription(a.getDescription());
res.add(action);
}
}
return res;
}
Aggregations