Search in sources :

Example 16 with ConfigDescriptionParameter

use of org.eclipse.smarthome.config.core.ConfigDescriptionParameter in project smarthome by eclipse.

the class TemperatureConditionType method initialize.

public static TemperatureConditionType initialize() {
    final ConfigDescriptionParameter temperature = ConfigDescriptionParameterBuilder.create(CONFIG_TEMPERATURE, Type.INTEGER).withRequired(true).withReadOnly(true).withMultiple(false).withLabel("Temperature").withDescription("Targeted room temperature").build();
    final ConfigDescriptionParameter operator = ConfigDescriptionParameterBuilder.create(CONFIG_OPERATOR, Type.TEXT).withRequired(true).withReadOnly(true).withMultiple(false).withLabel("Mode").withDescription("Heating/Cooling mode").build();
    final List<ConfigDescriptionParameter> config = new ArrayList<ConfigDescriptionParameter>();
    config.add(temperature);
    config.add(operator);
    Input currentTemperature = new Input(INPUT_CURRENT_TEMPERATURE, Integer.class.getName(), "Current Temperature", "Current room temperature", null, true, null, null);
    List<Input> input = new ArrayList<Input>();
    input.add(currentTemperature);
    return new TemperatureConditionType(config, input);
}
Also used : Input(org.eclipse.smarthome.automation.type.Input) ArrayList(java.util.ArrayList) ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter)

Example 17 with ConfigDescriptionParameter

use of org.eclipse.smarthome.config.core.ConfigDescriptionParameter in project smarthome by eclipse.

the class RuleEngineTest method testRuleConfigValue.

/**
 * test rule configurations with real values
 */
@Test
public void testRuleConfigValue() {
    RuleEngine ruleEngine = createRuleEngine();
    List<ConfigDescriptionParameter> configDescriptions = createConfigDescriptions();
    Configuration configurations = new Configuration();
    configurations.put("config1", 5);
    Rule rule4 = new Rule("rule4");
    rule4.setTriggers(createTriggers("typeUID"));
    rule4.setConditions(createConditions("typeUID"));
    rule4.setActions(createActions("typeUID"));
    rule4.setConfigurationDescriptions(configDescriptions);
    rule4.setConfiguration(configurations);
    ruleEngine.addRule(rule4, true);
    RuntimeRule rule4Get = ruleEngine.getRuntimeRule("rule4");
    Configuration rule4cfg = rule4Get.getConfiguration();
    List<ConfigDescriptionParameter> rule4cfgD = rule4Get.getConfigurationDescriptions();
    Assert.assertNotNull("Rule configuration is null", rule4cfg);
    Assert.assertTrue("Missing config property in rule copy", rule4cfg.containsKey("config1"));
    Assert.assertEquals("Wrong config value", new BigDecimal(5), rule4cfg.get("config1"));
    Assert.assertNotNull("Rule configuration description is null", rule4cfgD);
    Assert.assertEquals("Missing config description in rule copy", 1, rule4cfgD.size());
    ConfigDescriptionParameter rule4cfgDP = rule4cfgD.iterator().next();
    Assert.assertEquals("Wrong default value in config description", "3", rule4cfgDP.getDefault());
    Assert.assertEquals("Wrong context value in config description", "context1", rule4cfgDP.getContext());
    Assert.assertNotNull("Null options in config description", rule4cfgDP.getOptions());
    Assert.assertEquals("Wrong option value in config description", "1", rule4cfgDP.getOptions().get(0).getValue());
    Assert.assertEquals("Wrong option label in config description", "one", rule4cfgDP.getOptions().get(0).getLabel());
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter) Rule(org.eclipse.smarthome.automation.Rule) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 18 with ConfigDescriptionParameter

use of org.eclipse.smarthome.config.core.ConfigDescriptionParameter 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);
            }
        }
    }
}
Also used : ModuleType(org.eclipse.smarthome.automation.type.ModuleType) Configuration(org.eclipse.smarthome.config.core.Configuration) ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter) Module(org.eclipse.smarthome.automation.Module)

Example 19 with ConfigDescriptionParameter

use of org.eclipse.smarthome.config.core.ConfigDescriptionParameter in project smarthome by eclipse.

the class RuleEngine method validateConfiguration.

private void validateConfiguration(String uid, List<ConfigDescriptionParameter> configDescriptions, Map<String, Object> configurations) {
    if (configurations == null || configurations.isEmpty()) {
        if (isOptionalConfig(configDescriptions)) {
            return;
        } else {
            for (ConfigDescriptionParameter configParameter : configDescriptions) {
                if (configParameter.isRequired()) {
                    logger.error("Missing required configuration property '{}' for rule with UID '{}'!", configParameter.getName(), uid);
                }
            }
            throw new IllegalArgumentException("Missing required configuration properties!");
        }
    } else {
        for (ConfigDescriptionParameter configParameter : configDescriptions) {
            String configParameterName = configParameter.getName();
            processValue(configurations.remove(configParameterName), configParameter);
        }
        for (String name : configurations.keySet()) {
            logger.error("Extra configuration property '{}' for rule with UID '{}'!", name, uid);
        }
        if (!configurations.isEmpty()) {
            throw new IllegalArgumentException("Extra configuration properties!");
        }
    }
}
Also used : ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter)

Example 20 with ConfigDescriptionParameter

use of org.eclipse.smarthome.config.core.ConfigDescriptionParameter in project smarthome by eclipse.

the class StateConditionType method initialize.

public static StateConditionType initialize() {
    final ConfigDescriptionParameter state = ConfigDescriptionParameterBuilder.create(CONFIG_STATE, Type.TEXT).withRequired(true).withReadOnly(true).withMultiple(false).withLabel("State").withDescription("State of the unit").build();
    final List<ConfigDescriptionParameter> config = new ArrayList<ConfigDescriptionParameter>();
    config.add(state);
    Input leftOperand = new Input(INPUT_CURRENT_STATE, String.class.getName(), "Current State", "Current state of the unit", null, true, null, null);
    List<Input> input = new ArrayList<Input>();
    input.add(leftOperand);
    return new StateConditionType(config, input);
}
Also used : Input(org.eclipse.smarthome.automation.type.Input) ArrayList(java.util.ArrayList) ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter)

Aggregations

ConfigDescriptionParameter (org.eclipse.smarthome.config.core.ConfigDescriptionParameter)29 ArrayList (java.util.ArrayList)13 ConfigDescription (org.eclipse.smarthome.config.core.ConfigDescription)9 URI (java.net.URI)7 Configuration (org.eclipse.smarthome.config.core.Configuration)5 ParameterOption (org.eclipse.smarthome.config.core.ParameterOption)4 Test (org.junit.Test)4 Bundle (org.osgi.framework.Bundle)4 BigDecimal (java.math.BigDecimal)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Action (org.eclipse.smarthome.automation.Action)3 Condition (org.eclipse.smarthome.automation.Condition)3 Trigger (org.eclipse.smarthome.automation.Trigger)3 ConfigDescriptionParameterGroup (org.eclipse.smarthome.config.core.ConfigDescriptionParameterGroup)3 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)3 URISyntaxException (java.net.URISyntaxException)2 HashSet (java.util.HashSet)2 Rule (org.eclipse.smarthome.automation.Rule)2 Input (org.eclipse.smarthome.automation.type.Input)2