Search in sources :

Example 81 with Configuration

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

Example 82 with Configuration

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))));
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 83 with Configuration

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;
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 84 with Configuration

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"));
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) HashMap(java.util.HashMap) Thing(org.eclipse.smarthome.core.thing.Thing) Test(org.junit.Test)

Example 85 with Configuration

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);
    }
}
Also used : MqttBrokerConnection(org.eclipse.smarthome.io.transport.mqtt.MqttBrokerConnection) MqttBrokerConnectionConfig(org.eclipse.smarthome.io.transport.mqtt.MqttBrokerConnectionConfig) Configuration(org.eclipse.smarthome.config.core.Configuration) ConfigurationException(org.osgi.service.cm.ConfigurationException) MqttException(org.eclipse.smarthome.io.transport.mqtt.MqttException) NonNull(org.eclipse.jdt.annotation.NonNull) MqttService(org.eclipse.smarthome.io.transport.mqtt.MqttService) Modified(org.osgi.service.component.annotations.Modified)

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