Search in sources :

Example 56 with Configuration

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

the class HueBridgeHandler method updateBridgeThingConfiguration.

private void updateBridgeThingConfiguration(String userName) {
    Configuration config = editConfiguration();
    config.put(USER_NAME, userName);
    try {
        updateConfiguration(config);
        logger.debug("Updated configuration parameter {} to '{}'", USER_NAME, userName);
    } catch (IllegalStateException e) {
        logger.trace("Configuration update failed.", e);
        logger.warn("Unable to update configuration of Hue bridge.");
        logger.warn("Please configure the following user name manually: {}", userName);
    }
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration)

Example 57 with Configuration

use of org.eclipse.smarthome.config.core.Configuration 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));
}
Also used : Condition(org.eclipse.smarthome.automation.Condition) Action(org.eclipse.smarthome.automation.Action) Trigger(org.eclipse.smarthome.automation.Trigger) Configuration(org.eclipse.smarthome.config.core.Configuration) Module(org.eclipse.smarthome.automation.Module) Test(org.junit.Test)

Example 58 with Configuration

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

the class RuleEngineTest method createActions.

private List<Action> createActions(String type) {
    List<Action> actions = new ArrayList<Action>();
    Configuration configurations = new Configuration();
    configurations.put("a", "x");
    configurations.put("b", "y");
    configurations.put("c", "z");
    Map<String, String> inputs = new HashMap<String, String>(11);
    String ouputModuleId = "triggerId";
    String outputName = "triggerOutput";
    String inputName = "actionInput";
    inputs.put(inputName, ouputModuleId + "." + outputName);
    inputs.put("in6", ouputModuleId + "." + outputName);
    actions.add(new Action("actionId", type, configurations, inputs));
    return actions;
}
Also used : Action(org.eclipse.smarthome.automation.Action) Configuration(org.eclipse.smarthome.config.core.Configuration) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 59 with Configuration

use of org.eclipse.smarthome.config.core.Configuration 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 60 with Configuration

use of org.eclipse.smarthome.config.core.Configuration 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)

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