use of org.eclipse.smarthome.automation.module.core.handler.CompareConditionHandler in project smarthome by eclipse.
the class RuntimeRuleTest method compareConditionWorks.
@Test
public void compareConditionWorks() {
final Configuration conditionConfig = newRightOperatorConfig("ON", "=");
final Map<String, String> inputs = Stream.of(new SimpleEntry<>("input", "someTrigger.someoutput")).collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue()));
final Condition condition = new Condition("id", "core.GenericCompareCondition", conditionConfig, inputs);
final CompareConditionHandler handler = new CompareConditionHandler(condition);
assertSatisfiedHandlerInput(handler, true, OnOffType.ON);
assertSatisfiedHandlerInput(handler, true, "ON");
assertSatisfiedHandlerInput(handler, false, OnOffType.OFF);
assertSatisfiedHandlerInput(handler, false, "OFF");
condition.setConfiguration(newRightOperatorConfig("21", "="));
assertSatisfiedHandlerInput(handler, true, 21);
assertSatisfiedHandlerInput(handler, false, 22);
condition.setConfiguration(newRightOperatorConfig("21", "<"));
assertSatisfiedHandlerInput(handler, true, 20);
assertSatisfiedHandlerInput(handler, false, 22);
assertSatisfiedHandlerInput(handler, true, 20l);
assertSatisfiedHandlerInput(handler, false, 22l);
assertSatisfiedHandlerInput(handler, true, 20.9d);
assertSatisfiedHandlerInput(handler, false, 21.1d);
condition.setConfiguration(newRightOperatorConfig("21", "<="));
assertSatisfiedHandlerInput(handler, true, 20);
assertSatisfiedHandlerInput(handler, true, 21);
assertSatisfiedHandlerInput(handler, false, 22);
assertSatisfiedHandlerInput(handler, true, 20l);
assertSatisfiedHandlerInput(handler, true, 21l);
assertSatisfiedHandlerInput(handler, false, 22l);
assertSatisfiedHandlerInput(handler, true, 20.9d);
assertSatisfiedHandlerInput(handler, true, 21.0d);
assertSatisfiedHandlerInput(handler, false, 21.1d);
condition.setConfiguration(newRightOperatorConfig("21", "<"));
assertSatisfiedHandlerInput(handler, true, 20);
assertSatisfiedHandlerInput(handler, false, 22);
assertSatisfiedHandlerInput(handler, true, 20l);
assertSatisfiedHandlerInput(handler, false, 22l);
assertSatisfiedHandlerInput(handler, true, 20.9d);
assertSatisfiedHandlerInput(handler, false, 21.1d);
condition.setConfiguration(newRightOperatorConfig("21", "<="));
assertSatisfiedHandlerInput(handler, true, 20);
assertSatisfiedHandlerInput(handler, true, 21);
assertSatisfiedHandlerInput(handler, false, 22);
assertSatisfiedHandlerInput(handler, true, 20l);
assertSatisfiedHandlerInput(handler, true, 21l);
assertSatisfiedHandlerInput(handler, false, 22l);
assertSatisfiedHandlerInput(handler, true, 20.9d);
assertSatisfiedHandlerInput(handler, true, 21.0d);
assertSatisfiedHandlerInput(handler, false, 21.1d);
condition.setConfiguration(newRightOperatorConfig(".*anything.*", "matches"));
assertSatisfiedHandlerInput(handler, false, "something matches?");
assertSatisfiedHandlerInput(handler, true, "anything matches?");
Assert.assertFalse(handler.isSatisfied(Stream.of(new SimpleEntry<>("nothing", "nothing")).collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue()))));
condition.setConfiguration(newRightOperatorConfig("ONOFF", "matches"));
assertSatisfiedHandlerInput(handler, false, OnOffType.ON);
final Event event = ItemEventFactory.createStateEvent("itemName", OnOffType.OFF, "source");
condition.setConfiguration(newRightOperatorInputPropertyConfig(".*ON.*", "matches", "itemName"));
assertSatisfiedHandlerInput(handler, false, event);
condition.setConfiguration(newRightOperatorInputPropertyConfig("itemName", "matches", "itemName"));
assertSatisfiedHandlerInput(handler, true, event);
condition.setConfiguration(newRightOperatorConfig("null", "="));
assertSatisfiedHandlerInput(handler, true, null);
condition.setConfiguration(newRightOperatorConfig("notnull", "="));
assertSatisfiedHandlerInput(handler, false, null);
condition.setConfiguration(newRightOperatorConfig("ON", "<"));
assertSatisfiedHandlerInput(handler, false, OnOffType.ON);
condition.setConfiguration(newRightOperatorInputPropertyConfig("ON", "<", "nothing"));
assertSatisfiedHandlerInput(handler, false, event);
condition.setConfiguration(newRightOperatorInputPropertyConfig("ON", "=", "nothing"));
assertSatisfiedHandlerInput(handler, true, "ON");
}
use of org.eclipse.smarthome.automation.module.core.handler.CompareConditionHandler in project smarthome by eclipse.
the class CoreModuleHandlerFactory method internalCreate.
@Override
protected synchronized ModuleHandler internalCreate(final Module module, final String ruleUID) {
logger.trace("create {} -> {} : {}", module.getId(), module.getTypeUID(), ruleUID);
final String moduleTypeUID = module.getTypeUID();
if (module instanceof Trigger) {
if (GenericEventTriggerHandler.MODULE_TYPE_ID.equals(moduleTypeUID)) {
return new GenericEventTriggerHandler((Trigger) module, this.bundleContext);
} else if (ChannelEventTriggerHandler.MODULE_TYPE_ID.equals(moduleTypeUID)) {
return new ChannelEventTriggerHandler((Trigger) module, this.bundleContext);
} else if (ItemCommandTriggerHandler.MODULE_TYPE_ID.equals(moduleTypeUID)) {
return new ItemCommandTriggerHandler((Trigger) module, this.bundleContext);
} else if (ItemStateTriggerHandler.CHANGE_MODULE_TYPE_ID.equals(moduleTypeUID) || ItemStateTriggerHandler.UPDATE_MODULE_TYPE_ID.equals(moduleTypeUID)) {
return new ItemStateTriggerHandler((Trigger) module, this.bundleContext);
}
} else if (module instanceof Condition) {
// Handle conditions
if (ItemStateConditionHandler.ITEM_STATE_CONDITION.equals(moduleTypeUID)) {
ItemStateConditionHandler handler = new ItemStateConditionHandler((Condition) module);
handler.setItemRegistry(itemRegistry);
return handler;
} else if (GenericEventConditionHandler.MODULETYPE_ID.equals(moduleTypeUID)) {
return new GenericEventConditionHandler((Condition) module);
} else if (CompareConditionHandler.MODULE_TYPE.equals(moduleTypeUID)) {
return new CompareConditionHandler((Condition) module);
}
} else if (module instanceof Action) {
if (ItemCommandActionHandler.ITEM_COMMAND_ACTION.equals(moduleTypeUID)) {
final ItemCommandActionHandler postCommandActionHandler = new ItemCommandActionHandler((Action) module);
postCommandActionHandler.setEventPublisher(eventPublisher);
postCommandActionHandler.setItemRegistry(itemRegistry);
return postCommandActionHandler;
} else if (RuleEnablementActionHandler.UID.equals(moduleTypeUID)) {
return new RuleEnablementActionHandler((Action) module, ruleRegistry);
} else if (RunRuleActionHandler.UID.equals(moduleTypeUID)) {
return new RunRuleActionHandler((Action) module, ruleRegistry);
}
}
logger.error("The ModuleHandler is not supported:{}", moduleTypeUID);
return null;
}
Aggregations