use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.
the class NtpOSGiTest method testDateTimeChannelCalendarDefaultTimeZoneUpdate.
@Test
@Ignore("https://github.com/eclipse/smarthome/issues/5224")
public void testDateTimeChannelCalendarDefaultTimeZoneUpdate() {
Configuration configuration = new Configuration();
// Initialize with configuration with no time zone property set.
initialize(configuration, NtpBindingConstants.CHANNEL_DATE_TIME, ACCEPTED_ITEM_TYPE_DATE_TIME, null, null);
ZonedDateTime timeZoneIdFromItemRegistry = ((DateTimeType) getItemState(ACCEPTED_ITEM_TYPE_DATE_TIME)).getZonedDateTime();
ZoneOffset expectedOffset;
if (timeZoneIdFromItemRegistry.getZone().getRules().isDaylightSavings(timeZoneIdFromItemRegistry.toInstant())) {
expectedOffset = ZoneOffset.of("+03:00");
} else {
expectedOffset = ZoneOffset.of("+02:00");
}
assertEquals(expectedOffset, timeZoneIdFromItemRegistry.getOffset());
}
use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.
the class NtpOSGiTest method testStringChannelTimeZoneUpdate.
@Test
public void testStringChannelTimeZoneUpdate() {
final String expectedTimeZonePDT = "PDT";
final String expectedTimeZonePST = "PST";
Configuration configuration = new Configuration();
configuration.put(NtpBindingConstants.PROPERTY_TIMEZONE, TEST_TIME_ZONE_ID);
Configuration channelConfig = new Configuration();
/*
* Set the format of the date, so it is updated in the item registry in
* a format from which we can easily get the time zone.
*/
channelConfig.put(NtpBindingConstants.PROPERTY_DATE_TIME_FORMAT, TEST_DATE_TIME_FORMAT);
initialize(configuration, NtpBindingConstants.CHANNEL_STRING, ACCEPTED_ITEM_TYPE_STRING, channelConfig, null);
String timeZoneFromItemRegistry = getStringChannelTimeZoneFromItemRegistry();
assertThat(timeZoneFromItemRegistry, is(anyOf(equalTo(expectedTimeZonePDT), equalTo(expectedTimeZonePST))));
}
use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.
the class AutomaticInboxProcessor method getRepresentationPropertyValueForThing.
@Nullable
private String getRepresentationPropertyValueForThing(Thing thing) {
ThingType thingType = thingTypeRegistry.getThingType(thing.getThingTypeUID());
if (thingType != null) {
String representationProperty = thingType.getRepresentationProperty();
if (representationProperty == null) {
return null;
}
Map<String, String> properties = thing.getProperties();
if (properties.containsKey(representationProperty)) {
return properties.get(representationProperty);
}
Configuration configuration = thing.getConfiguration();
if (configuration.containsKey(representationProperty)) {
return String.valueOf(configuration.get(representationProperty));
}
}
return null;
}
use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.
the class PersistentInboxTest method testConfigUpdateNormalization_withConfigDescription.
@Test
public void testConfigUpdateNormalization_withConfigDescription() throws Exception {
Map<String, Object> props = new HashMap<>();
props.put("foo", "1");
Configuration config = new Configuration(props);
Thing thing = ThingBuilder.create(THING_TYPE_UID, THING_UID).withConfiguration(config).build();
configureConfigDescriptionRegistryMock("foo", Type.TEXT);
when(thingRegistry.get(eq(THING_UID))).thenReturn(thing);
assertTrue(thing.getConfiguration().get("foo") instanceof String);
inbox.add(DiscoveryResultBuilder.create(THING_UID).withProperty("foo", 3).build());
assertTrue(thing.getConfiguration().get("foo") instanceof String);
assertEquals("3", thing.getConfiguration().get("foo"));
}
use of org.eclipse.smarthome.config.core.Configuration in project smarthome by eclipse.
the class MqttBrokerConnectionServiceInstance method modified.
/**
* Create broker connections based on the service configuration. This will disconnect and
* discard all existing textual configured brokers.
*/
@Modified
public void modified(@Nullable Map<String, Object> configMap) {
if (connection != null) {
connection.stop();
}
if (configMap == null || configMap.isEmpty() || mqttService == null) {
return;
}
@NonNull final MqttService service = (@NonNull MqttService) mqttService;
// Parse configuration
MqttBrokerConnectionConfig config = new Configuration(configMap).as(MqttBrokerConnectionConfig.class);
try {
// Compute brokerID and make sure it is not empty
String brokerID = config.getBrokerID();
if (StringUtils.isBlank(brokerID) || brokerID == null) {
logger.warn("Ignore invalid broker connection configuration: {}", config);
return;
}
// Add connection and make sure it succeeded
MqttBrokerConnection c = service.addBrokerConnection(brokerID, config);
connection = c;
if (c == null) {
logger.warn("Ignore existing broker connection configuration for: {}", brokerID);
return;
}
// Start connection
c.start();
} catch (ConfigurationException | IllegalArgumentException e) {
logger.warn("MqttBroker connection configuration faulty: {}", e.getMessage());
} catch (MqttException e) {
logger.warn("MqttBroker start failed: {}", e.getMessage(), e);
}
}
Aggregations