use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.
the class ActionDTOMapper method mapDto.
public static Action mapDto(final ActionDTO actionDto) {
final Action action = new Action(actionDto.id, actionDto.type, new Configuration(actionDto.configuration), actionDto.inputs);
action.setLabel(actionDto.label);
action.setDescription(actionDto.description);
return action;
}
use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.
the class RuleResource method updateConfiguration.
@PUT
@Path("/{ruleUID}/config")
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Sets the rule configuration values.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 404, message = "Rule corresponding to the given UID does not found.") })
public Response updateConfiguration(@PathParam("ruleUID") @ApiParam(value = "ruleUID", required = true) String ruleUID, @ApiParam(value = "config") Map<String, Object> configurationParameters) throws IOException {
Map<String, Object> config = ConfigUtil.normalizeTypes(configurationParameters);
Rule rule = ruleRegistry.get(ruleUID);
if (rule == null) {
logger.info("Received HTTP PUT request for update config at '{}' for the unknown rule '{}'.", uriInfo.getPath(), ruleUID);
return Response.status(Status.NOT_FOUND).build();
} else {
rule.setConfiguration(new Configuration(config));
ruleRegistry.update(rule);
return Response.ok(null, MediaType.TEXT_PLAIN).build();
}
}
use of org.eclipse.smarthome.config.core.Configuration 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();
}
use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.
the class SampleJavaDemo method addRule.
void addRule() {
final Configuration triggerConfig = new Configuration();
triggerConfig.put("itemName", "DemoSwitch");
final Trigger ruleTrigger = new Trigger("RuleTrigger", "ItemStateChangeTrigger", triggerConfig);
final Configuration actionConfig = new Configuration();
actionConfig.put("itemName", "DemoDimmer");
actionConfig.put("command", "ON");
final Action ruleAction = new Action("RuleAction", "ItemPostCommandAction", actionConfig, null);
final ArrayList<Trigger> triggers = new ArrayList<Trigger>();
triggers.add(ruleTrigger);
final ArrayList<Action> actions = new ArrayList<Action>();
actions.add(ruleAction);
final Rule r = new Rule(RULE_UID, triggers, null, actions, null, null, null, Visibility.VISIBLE);
r.setName("DemoRule");
ruleRegistry.add(r);
}
use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.
the class WelcomeHomeRulesProvider method createACRule.
/**
* This method creates a rule from template by using UID, templateUID and configuration.
*
* @return the created rule
*/
private Rule createACRule() {
Configuration config = new Configuration();
config.put(CONFIG_UNIT, "Air Conditioner");
config.put(CONFIG_EXPECTED_RESULT, "The air conditioner is switched on.");
config.put(AirConditionerRuleTemplate.CONFIG_TARGET_TEMPERATURE, new Integer(18));
config.put(AirConditionerRuleTemplate.CONFIG_OPERATION, TemperatureConditionType.OPERATOR_HEATING);
Rule rule = new Rule(AC_UID);
rule.setTemplateUID(AirConditionerRuleTemplate.UID);
rule.setConfiguration(config);
return rule;
}
Aggregations