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);
}
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());
}
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);
}
}
}
}
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!");
}
}
}
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);
}
Aggregations