Search in sources :

Example 61 with Configuration

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;
}
Also used : Action(org.eclipse.smarthome.automation.Action) Configuration(org.eclipse.smarthome.config.core.Configuration)

Example 62 with Configuration

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();
    }
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) Rule(org.eclipse.smarthome.automation.Rule) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 63 with Configuration

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();
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) Rule(org.eclipse.smarthome.automation.Rule) Module(org.eclipse.smarthome.automation.Module) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 64 with Configuration

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);
}
Also used : Action(org.eclipse.smarthome.automation.Action) Trigger(org.eclipse.smarthome.automation.Trigger) Configuration(org.eclipse.smarthome.config.core.Configuration) ArrayList(java.util.ArrayList) Rule(org.eclipse.smarthome.automation.Rule)

Example 65 with Configuration

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;
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) Rule(org.eclipse.smarthome.automation.Rule)

Aggregations

Configuration (org.eclipse.smarthome.config.core.Configuration)119 Test (org.junit.Test)27 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)19 ArrayList (java.util.ArrayList)18 Thing (org.eclipse.smarthome.core.thing.Thing)18 Action (org.eclipse.smarthome.automation.Action)16 Trigger (org.eclipse.smarthome.automation.Trigger)16 Rule (org.eclipse.smarthome.automation.Rule)15 Before (org.junit.Before)14 Condition (org.eclipse.smarthome.automation.Condition)10 Bridge (org.eclipse.smarthome.core.thing.Bridge)9 ApiOperation (io.swagger.annotations.ApiOperation)8 ApiResponses (io.swagger.annotations.ApiResponses)8 HashMap (java.util.HashMap)8 ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)8 Path (javax.ws.rs.Path)7 IOException (java.io.IOException)6 BigDecimal (java.math.BigDecimal)6 Consumes (javax.ws.rs.Consumes)6 RuleRegistry (org.eclipse.smarthome.automation.RuleRegistry)6