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