use of org.eclipse.smarthome.automation.Trigger in project smarthome by eclipse.
the class CompositeTriggerHandler method setRuleEngineCallback.
/**
* The {@link CompositeTriggerHandler} sets itself as callback to the child triggers and store the callback to the
* rule engine. In this way the trigger of composite type will be notified always when some of the child triggers
* are triggered and has an opportunity to set the outputs of parent trigger to the rule context.
*
* @see org.eclipse.smarthome.automation.handler.TriggerHandler#setRuleEngineCallback(org.eclipse.smarthome.automation.handler.RuleEngineCallback)
*/
@Override
public void setRuleEngineCallback(RuleEngineCallback ruleCallback) {
this.ruleCallback = ruleCallback;
if (ruleCallback != null) {
// could be called with 'null' from dispose
List<Trigger> children = getChildren();
for (Trigger child : children) {
TriggerHandler handler = moduleHandlerMap.get(child);
handler.setRuleEngineCallback(this);
}
}
}
use of org.eclipse.smarthome.automation.Trigger in project smarthome by eclipse.
the class RuleTemplateRegistry method copyTriggers.
private 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(t.getLabel());
trigger.setDescription(t.getDescription());
res.add(trigger);
}
}
return res;
}
use of org.eclipse.smarthome.automation.Trigger 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.automation.Trigger in project smarthome by eclipse.
the class ConnectionValidator method checkConnection.
/**
* The method validates the connection between outputs of list of triggers to the action's or condition's input. It
* checks if the input is unconnected and compatibility of data types of the input and connected output. Throws
* exception if they are incompatible.
*
* @param connection that should be validated
* @param input that should be validated
* @param triggers is a list with triggers of the rule on which the action belongs
* @throws IllegalArgumentException when validation fails.
*/
private static void checkConnection(Connection connection, Input input, List<Trigger> triggers) {
Map<String, Trigger> triggersMap = new HashMap<String, Trigger>();
for (Trigger trigger : triggers) {
triggersMap.put(trigger.getId(), trigger);
}
String moduleId = connection.getOuputModuleId();
String msg = " Invalid Connection \"" + connection.getInputName() + "\" : ";
if (moduleId != null) {
Trigger trigger = triggersMap.get(moduleId);
if (trigger == null) {
throw new IllegalArgumentException(msg + " Trigger with ID \"" + moduleId + "\" does not exist!");
}
String triggerTypeUID = trigger.getTypeUID();
TriggerType triggerType = (TriggerType) mtRegistry.get(triggerTypeUID);
if (triggerType == null) {
throw new IllegalArgumentException(msg + " Trigger Type with UID \"" + triggerTypeUID + "\" does not exist!");
}
checkCompatibility(msg, connection, input, triggerType.getOutputs());
}
}
use of org.eclipse.smarthome.automation.Trigger 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);
}
}
Aggregations