use of org.eclipse.smarthome.automation.Module in project smarthome by eclipse.
the class ReferenceResolverUtilTest method testModuleInputResolving.
@Test
public void testModuleInputResolving() {
// test Composite child Module(condition) context
Module condition = new Condition(null, null, null, compositeChildModuleInputsReferences);
Map<String, Object> conditionContext = ReferenceResolverUtil.getCompositeChildContext(condition, context);
Assert.assertEquals(conditionContext, expectedCompositeChildModuleContext);
// test Composite child Module(action) context
Module action = new Action(null, null, null, compositeChildModuleInputsReferences);
Map<String, Object> actionContext = ReferenceResolverUtil.getCompositeChildContext(action, context);
Assert.assertEquals(actionContext, expectedCompositeChildModuleContext);
}
use of org.eclipse.smarthome.automation.Module in project smarthome by eclipse.
the class ReferenceResolverUtilTest method testModuleConfigurationResolving.
@Test
public void testModuleConfigurationResolving() {
// test trigger configuration..
Module trigger = new Trigger(null, null, new Configuration(moduleConfiguration));
ReferenceResolverUtil.updateModuleConfiguration(trigger, context);
Assert.assertEquals(trigger.getConfiguration(), new Configuration(expectedModuleConfiguration));
// test condition configuration..
Module condition = new Condition(null, null, new Configuration(moduleConfiguration), null);
ReferenceResolverUtil.updateModuleConfiguration(condition, context);
Assert.assertEquals(condition.getConfiguration(), new Configuration(expectedModuleConfiguration));
// test action configuration..
Module action = new Action(null, null, new Configuration(moduleConfiguration), null);
ReferenceResolverUtil.updateModuleConfiguration(action, context);
Assert.assertEquals(action.getConfiguration(), new Configuration(expectedModuleConfiguration));
}
use of org.eclipse.smarthome.automation.Module in project smarthome by eclipse.
the class RuleEngine method setRule.
/**
* This method tries to initialize the rule. It uses available {@link ModuleHandlerFactory}s to create
* {@link ModuleHandler}s for all {@link Module}s of the {@link Rule} and to link them. When all the modules have
* associated module handlers then the {@link Rule} is initialized and it is ready to working. It goes into idle
* state. Otherwise the Rule stays into not initialized and continue to wait missing handlers, module types or
* templates.
*
* @param rUID a UID of rule which tries to be initialized.
*/
private void setRule(RuntimeRule runtimeRule) {
if (isDisposed) {
return;
}
String rUID = runtimeRule.getUID();
setRuleStatusInfo(rUID, new RuleStatusInfo(RuleStatus.INITIALIZING), true);
if (runtimeRule.getTemplateUID() != null) {
setRuleStatusInfo(rUID, new RuleStatusInfo(RuleStatus.UNINITIALIZED, RuleStatusDetail.TEMPLATE_MISSING_ERROR), true);
// Template is not available (when a template is resolved it removes tempalteUID configuration
return;
// property). The rule must stay NOT_INITIALISED.
}
List<Module> modules = runtimeRule.getModules(Module.class);
for (Module m : modules) {
updateMapModuleTypeToRule(rUID, m.getTypeUID());
}
String errMsgs;
try {
validateModuleIDs(modules);
resolveConfiguration(runtimeRule);
autoMapConnections(runtimeRule);
ConnectionValidator.validateConnections(runtimeRule);
} catch (RuntimeException e) {
errMsgs = "\n Validation of rule " + rUID + " has failed! " + e.getLocalizedMessage();
// change state to NOTINITIALIZED
setRuleStatusInfo(rUID, new RuleStatusInfo(RuleStatus.UNINITIALIZED, RuleStatusDetail.CONFIGURATION_ERROR, errMsgs.trim()), true);
return;
}
errMsgs = setModuleHandlers(rUID, modules);
if (errMsgs == null) {
register(runtimeRule);
// change state to IDLE
setRuleStatusInfo(rUID, new RuleStatusInfo(RuleStatus.IDLE), true);
Future f = scheduleTasks.remove(rUID);
if (f != null) {
if (!f.isDone()) {
f.cancel(true);
}
}
if (scheduleTasks.isEmpty()) {
if (executor != null) {
executor.shutdown();
executor = null;
}
}
} else {
// change state to NOTINITIALIZED
setRuleStatusInfo(rUID, new RuleStatusInfo(RuleStatus.UNINITIALIZED, RuleStatusDetail.HANDLER_INITIALIZING_ERROR, errMsgs), true);
unregister(runtimeRule);
}
}
use of org.eclipse.smarthome.automation.Module in project smarthome by eclipse.
the class RuleEngine method normalizeModuleConfigurations.
private <T extends Module> void normalizeModuleConfigurations(List<@NonNull T> modules) {
for (Module module : modules) {
Configuration config = module.getConfiguration();
if (config != null) {
String type = module.getTypeUID();
ModuleType mt = mtRegistry.get(type);
if (mt != null) {
List<ConfigDescriptionParameter> configDescriptions = mt.getConfigurationDescriptions();
Map<String, ConfigDescriptionParameter> mapConfigDescriptions = getConfigDescriptionMap(configDescriptions);
normalizeConfiguration(config, mapConfigDescriptions);
}
}
}
}
use of org.eclipse.smarthome.automation.Module in project smarthome by eclipse.
the class RuleResource method setModuleConfigParam.
@PUT
@Path("/{ruleUID}/{moduleCategory}/{id}/config/{param}")
@ApiOperation(value = "Sets the module's configuration parameter value.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 404, message = "Rule corresponding to the given UID does not found or does not have a module with such Category and ID.") })
@Consumes(MediaType.TEXT_PLAIN)
public Response setModuleConfigParam(@PathParam("ruleUID") @ApiParam(value = "ruleUID", required = true) String ruleUID, @PathParam("moduleCategory") @ApiParam(value = "moduleCategory", required = true) String moduleCategory, @PathParam("id") @ApiParam(value = "id", required = true) String id, @PathParam("param") @ApiParam(value = "param", required = true) String param, @ApiParam(value = "value", required = true) String value) {
Rule rule = ruleRegistry.get(ruleUID);
if (rule != null) {
Module module = getModule(rule, moduleCategory, id);
if (module != null) {
Configuration configuration = module.getConfiguration();
configuration.put(param, ConfigUtil.normalizeType(value));
module.setConfiguration(configuration);
ruleRegistry.update(rule);
return Response.ok(null, MediaType.TEXT_PLAIN).build();
}
}
return Response.status(Status.NOT_FOUND).build();
}
Aggregations