Search in sources :

Example 26 with Configuration

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

the class BaseThingHandler method handleConfigurationUpdate.

@Override
public void handleConfigurationUpdate(Map<String, Object> configurationParameters) {
    if (!isModifyingCurrentConfig(configurationParameters)) {
        return;
    }
    validateConfigurationParameters(configurationParameters);
    // can be overridden by subclasses
    Configuration configuration = editConfiguration();
    for (Entry<String, Object> configurationParameter : configurationParameters.entrySet()) {
        configuration.put(configurationParameter.getKey(), configurationParameter.getValue());
    }
    if (isInitialized()) {
        // persist new configuration and reinitialize handler
        dispose();
        updateConfiguration(configuration);
        initialize();
    } else {
        // persist new configuration and notify Thing Manager
        updateConfiguration(configuration);
        callback.configurationUpdated(getThing());
    }
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration)

Example 27 with Configuration

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

the class ChannelDTOMapper method map.

/**
 * Maps channel DTO into channel object.
 *
 * @param channelDTO the channel DTO
 * @return the channel object
 */
public static Channel map(ChannelDTO channelDTO) {
    ChannelUID channelUID = new ChannelUID(channelDTO.uid);
    ChannelTypeUID channelTypeUID = new ChannelTypeUID(channelDTO.channelTypeUID);
    return ChannelBuilder.create(channelUID, channelDTO.itemType).withConfiguration(new Configuration(channelDTO.configuration)).withLabel(channelDTO.label).withDescription(channelDTO.description).withProperties(channelDTO.properties).withType(channelTypeUID).withDefaultTags(channelDTO.defaultTags).withKind(ChannelKind.parse(channelDTO.kind)).build();
}
Also used : ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) Configuration(org.eclipse.smarthome.config.core.Configuration) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID)

Example 28 with Configuration

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

the class WelcomeHomeCommands method settings.

/**
 * This method is used to configure the provided rules.
 *
 * @param params
 *            provides external data, that is used for configuring the rules.
 * @param console
 *            provides the output of the command.
 */
private void settings(String[] params, Console console) {
    if (params.length < 2) {
        console.println("Missing required parameters");
        return;
    }
    Configuration config = rulesProvider.rules.get(WelcomeHomeRulesProvider.AC_UID).getConfiguration();
    if (params[0] != null && (params[0].equalsIgnoreCase(TemperatureConditionType.OPERATOR_HEATING) || params[0].equalsIgnoreCase(TemperatureConditionType.OPERATOR_COOLING))) {
        config.put(AirConditionerRuleTemplate.CONFIG_OPERATION, params[0]);
    } else {
        console.println("Invalid parameter value of the parameter \"mode\". Should be \"" + TemperatureConditionType.OPERATOR_HEATING + "\" or \"" + TemperatureConditionType.OPERATOR_COOLING + "\"");
        return;
    }
    if (params[1] != null) {
        Integer temperature;
        try {
            temperature = new Integer(params[1]);
            config.put(AirConditionerRuleTemplate.CONFIG_TARGET_TEMPERATURE, temperature);
        } catch (NumberFormatException e) {
            console.println("Invalid parameter value of the parameter \"temperature\". Should be number.");
            return;
        }
    }
    rulesProvider.update(WelcomeHomeRulesProvider.AC_UID, AirConditionerRuleTemplate.UID, config);
    console.println("SUCCESS");
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration)

Example 29 with Configuration

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

the class AirConditionerRuleTemplate method initialize.

public static AirConditionerRuleTemplate initialize() {
    // initialize triggers
    List<Trigger> triggers = new ArrayList<Trigger>();
    triggers.add(new Trigger(TRIGGER_ID, AirConditionerTriggerType.UID, null));
    // initialize conditions
    // here the tricky part is the giving a value to the condition configuration parameter.
    Configuration conditionConfig = new Configuration();
    conditionConfig.put(StateConditionType.CONFIG_STATE, "on");
    // here the tricky part is the referring into the condition input - trigger output.
    // The syntax is a similar to the JUEL syntax.
    Map<String, String> conditionInputs = new HashMap<String, String>();
    conditionInputs.put(StateConditionType.INPUT_CURRENT_STATE, TRIGGER_ID + "." + StateConditionType.INPUT_CURRENT_STATE);
    Condition stateCondition = new Condition("AirConditionerStateCondition", StateConditionType.UID, conditionConfig, conditionInputs);
    // here the tricky part is the referring into the condition configuration parameter - the
    // template configuration parameter. The syntax is a similar to the JUEL syntax.
    conditionConfig = new Configuration();
    conditionConfig.put(TemperatureConditionType.CONFIG_TEMPERATURE, "$" + CONFIG_TARGET_TEMPERATURE);
    conditionConfig.put(TemperatureConditionType.CONFIG_OPERATOR, "$" + CONFIG_OPERATION);
    // here the tricky part is the referring into the condition input - trigger output.
    // The syntax is a similar to the JUEL syntax.
    conditionInputs = new HashMap<String, String>();
    conditionInputs.put(TemperatureConditionType.INPUT_CURRENT_TEMPERATURE, TRIGGER_ID + "." + TemperatureConditionType.INPUT_CURRENT_TEMPERATURE);
    Condition temperatureCondition = new Condition("AirConditionerTemperatureCondition", TemperatureConditionType.UID, conditionConfig, conditionInputs);
    List<Condition> conditions = new ArrayList<Condition>();
    conditions.add(stateCondition);
    conditions.add(temperatureCondition);
    // initialize actions - here the tricky part is the referring into the action configuration parameter - the
    // template configuration parameter. The syntax is a similar to the JUEL syntax.
    Configuration actionConfig = new Configuration();
    actionConfig.put(WelcomeHomeActionType.CONFIG_DEVICE, "$" + WelcomeHomeRulesProvider.CONFIG_UNIT);
    actionConfig.put(WelcomeHomeActionType.CONFIG_RESULT, "$" + WelcomeHomeRulesProvider.CONFIG_EXPECTED_RESULT);
    List<Action> actions = new ArrayList<Action>();
    actions.add(new Action("AirConditionerSwitchOnAction", WelcomeHomeActionType.UID, actionConfig, null));
    // initialize configDescriptions
    List<ConfigDescriptionParameter> configDescriptions = new ArrayList<ConfigDescriptionParameter>();
    final ConfigDescriptionParameter device = ConfigDescriptionParameterBuilder.create(WelcomeHomeRulesProvider.CONFIG_UNIT, Type.TEXT).withRequired(true).withReadOnly(true).withMultiple(false).withLabel("Device").withDescription("Device description").build();
    final ConfigDescriptionParameter result = ConfigDescriptionParameterBuilder.create(WelcomeHomeRulesProvider.CONFIG_EXPECTED_RESULT, Type.TEXT).withRequired(true).withReadOnly(true).withMultiple(false).withLabel("Result").withDescription("Result description").build();
    final ConfigDescriptionParameter temperature = ConfigDescriptionParameterBuilder.create(CONFIG_TARGET_TEMPERATURE, Type.INTEGER).withRequired(true).withReadOnly(true).withMultiple(false).withLabel("Target temperature").withDescription("Indicates the target temperature.").build();
    final ConfigDescriptionParameter operation = ConfigDescriptionParameterBuilder.create(CONFIG_OPERATION, Type.TEXT).withRequired(true).withReadOnly(true).withMultiple(false).withLabel("Heating/Cooling").withDescription("Indicates Heating or Cooling is set.").build();
    configDescriptions.add(device);
    configDescriptions.add(result);
    configDescriptions.add(temperature);
    configDescriptions.add(operation);
    // initialize tags
    Set<String> tags = new HashSet<String>();
    tags.add("AirConditioner");
    tags.add("LivingRoom");
    // create the template
    return new AirConditionerRuleTemplate(tags, triggers, conditions, actions, configDescriptions);
}
Also used : Condition(org.eclipse.smarthome.automation.Condition) Action(org.eclipse.smarthome.automation.Action) Configuration(org.eclipse.smarthome.config.core.Configuration) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Trigger(org.eclipse.smarthome.automation.Trigger) ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter) HashSet(java.util.HashSet)

Example 30 with Configuration

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

the class NtpOSGiTest method testDateTimeChannelTimeZoneUpdate.

@Test
@Ignore("https://github.com/eclipse/smarthome/issues/5224")
public void testDateTimeChannelTimeZoneUpdate() {
    Configuration configuration = new Configuration();
    configuration.put(NtpBindingConstants.PROPERTY_TIMEZONE, TEST_TIME_ZONE_ID);
    initialize(configuration, NtpBindingConstants.CHANNEL_DATE_TIME, ACCEPTED_ITEM_TYPE_DATE_TIME, null, null);
    String testItemState = getItemState(ACCEPTED_ITEM_TYPE_DATE_TIME).toString();
    assertFormat(testItemState, DateTimeType.DATE_PATTERN_WITH_TZ_AND_MS);
    ZonedDateTime timeZoneFromItemRegistry = ((DateTimeType) getItemState(ACCEPTED_ITEM_TYPE_DATE_TIME)).getZonedDateTime();
    ZoneOffset expectedOffset;
    if (timeZoneFromItemRegistry.getZone().getRules().isDaylightSavings(timeZoneFromItemRegistry.toInstant())) {
        expectedOffset = ZoneOffset.of("-07:00");
    } else {
        expectedOffset = ZoneOffset.of("-08:00");
    }
    assertEquals(expectedOffset, timeZoneFromItemRegistry.getOffset());
}
Also used : DateTimeType(org.eclipse.smarthome.core.library.types.DateTimeType) Configuration(org.eclipse.smarthome.config.core.Configuration) ZonedDateTime(java.time.ZonedDateTime) ZoneOffset(java.time.ZoneOffset) Ignore(org.junit.Ignore) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

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