Search in sources :

Example 36 with Configuration

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

the class NtpOSGiTest method testDateTimeChannelDefaultTimeZoneUpdate.

@Test
public void testDateTimeChannelDefaultTimeZoneUpdate() {
    ZonedDateTime zoned = ZonedDateTime.now();
    ZoneOffset expectedTimeZone = zoned.getOffset();
    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);
    String testItemState = getItemState(ACCEPTED_ITEM_TYPE_DATE_TIME).toString();
    assertFormat(testItemState, DateTimeType.DATE_PATTERN_WITH_TZ_AND_MS);
    ZoneOffset timeZoneFromItemRegistry = new DateTimeType(testItemState).getZonedDateTime().getOffset();
    assertEquals(expectedTimeZone, timeZoneFromItemRegistry);
}
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) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 37 with Configuration

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

the class NtpOSGiTest method testStringChannelDefaultFormatting.

@Test
public void testStringChannelDefaultFormatting() {
    Configuration configuration = new Configuration();
    // Initialize with configuration with no property for formatting set.
    initialize(configuration, NtpBindingConstants.CHANNEL_STRING, ACCEPTED_ITEM_TYPE_STRING, null, null);
    String dateFromItemRegistryString = getItemState(ACCEPTED_ITEM_TYPE_STRING).toString();
    assertFormat(dateFromItemRegistryString, NtpHandler.DATE_PATTERN_WITH_TZ);
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 38 with Configuration

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

the class NtpHandler method initialize.

@Override
public void initialize() {
    try {
        logger.debug("Initializing NTP handler for '{}'.", getThing().getUID());
        Configuration config = getThing().getConfiguration();
        hostname = config.get(PROPERTY_NTP_SERVER_HOST).toString();
        port = (BigDecimal) config.get(PROPERTY_NTP_SERVER_PORT);
        refreshInterval = (BigDecimal) config.get(PROPERTY_REFRESH_INTERVAL);
        refreshNtp = (BigDecimal) config.get(PROPERTY_REFRESH_NTP);
        refreshNtpCount = 0;
        try {
            Object timeZoneConfigValue = config.get(PROPERTY_TIMEZONE);
            if (timeZoneConfigValue != null) {
                timeZone = TimeZone.getTimeZone(timeZoneConfigValue.toString());
            } else {
                timeZone = TimeZone.getDefault();
                logger.debug("{} using default TZ '{}', because configuration property '{}' is null.", getThing().getUID(), timeZone, PROPERTY_TIMEZONE);
            }
        } catch (Exception e) {
            timeZone = TimeZone.getDefault();
            logger.debug("{} using default TZ '{}' due to an occurred exception: ", getThing().getUID(), timeZone, e);
        }
        try {
            Object localeStringConfigValue = config.get(PROPERTY_LOCALE);
            if (localeStringConfigValue != null) {
                locale = new Locale(localeStringConfigValue.toString());
            } else {
                locale = localeProvider.getLocale();
                logger.debug("{} using default locale '{}', because configuration property '{}' is null.", getThing().getUID(), locale, PROPERTY_LOCALE);
            }
        } catch (Exception e) {
            locale = localeProvider.getLocale();
            logger.debug("{} using default locale '{}' due to an occurred exception: ", getThing().getUID(), locale, e);
        }
        dateTimeChannelUID = new ChannelUID(getThing().getUID(), CHANNEL_DATE_TIME);
        stringChannelUID = new ChannelUID(getThing().getUID(), CHANNEL_STRING);
        try {
            Channel stringChannel = getThing().getChannel(stringChannelUID.getId());
            if (stringChannel != null) {
                Configuration cfg = stringChannel.getConfiguration();
                String dateTimeFormatString = cfg.get(PROPERTY_DATE_TIME_FORMAT).toString();
                if (!(dateTimeFormatString == null || dateTimeFormatString.isEmpty())) {
                    dateTimeFormat = DateTimeFormatter.ofPattern(dateTimeFormatString);
                } else {
                    logger.debug("No format set in channel config for {}. Using default format.", stringChannelUID);
                    dateTimeFormat = DateTimeFormatter.ofPattern(DATE_PATTERN_WITH_TZ);
                }
            } else {
                logger.debug("Missing channel: '{}'", stringChannelUID.getId());
            }
        } catch (RuntimeException ex) {
            logger.debug("No channel config or invalid format for {}. Using default format. ({})", stringChannelUID, ex.getMessage());
            dateTimeFormat = DateTimeFormatter.ofPattern(DATE_PATTERN_WITH_TZ);
        }
        SDF.setTimeZone(timeZone);
        dateTimeFormat.withZone(timeZone.toZoneId());
        logger.debug("Initialized NTP handler '{}' with configuration: host '{}', refresh interval {}, timezone {}, locale {}.", getThing().getUID(), hostname, refreshInterval, timeZone, locale);
        startAutomaticRefresh();
    } catch (Exception ex) {
        logger.error("Error occurred while initializing NTP handler: {}", ex.getMessage(), ex);
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "@text/offline.conf-error-init-handler");
    }
}
Also used : Locale(java.util.Locale) Configuration(org.eclipse.smarthome.config.core.Configuration) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Channel(org.eclipse.smarthome.core.thing.Channel) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 39 with Configuration

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

the class LifxLightHandler method getPowerOnTemperature.

private PercentType getPowerOnTemperature() {
    ChannelUID channelUID = new ChannelUID(getThing().getUID(), LifxBindingConstants.CHANNEL_TEMPERATURE);
    Channel channel = getThing().getChannel(channelUID.getId());
    if (channel == null) {
        return null;
    }
    Configuration configuration = channel.getConfiguration();
    Object powerOnTemperature = configuration.get(LifxBindingConstants.CONFIG_PROPERTY_POWER_ON_TEMPERATURE);
    if (powerOnTemperature != null) {
        return new PercentType(powerOnTemperature.toString());
    }
    return null;
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Channel(org.eclipse.smarthome.core.thing.Channel) PercentType(org.eclipse.smarthome.core.library.types.PercentType) LifxMessageUtil.increaseDecreasePercentType(org.eclipse.smarthome.binding.lifx.internal.util.LifxMessageUtil.increaseDecreasePercentType)

Example 40 with Configuration

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

the class LifxLightHandler method getPowerOnBrightness.

private PercentType getPowerOnBrightness() {
    Channel channel = null;
    if (product.isColor()) {
        ChannelUID channelUID = new ChannelUID(getThing().getUID(), LifxBindingConstants.CHANNEL_COLOR);
        channel = getThing().getChannel(channelUID.getId());
    } else {
        ChannelUID channelUID = new ChannelUID(getThing().getUID(), LifxBindingConstants.CHANNEL_BRIGHTNESS);
        channel = getThing().getChannel(channelUID.getId());
    }
    if (channel == null) {
        return null;
    }
    Configuration configuration = channel.getConfiguration();
    Object powerOnBrightness = configuration.get(LifxBindingConstants.CONFIG_PROPERTY_POWER_ON_BRIGHTNESS);
    return powerOnBrightness == null ? null : new PercentType(powerOnBrightness.toString());
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Channel(org.eclipse.smarthome.core.thing.Channel) PercentType(org.eclipse.smarthome.core.library.types.PercentType) LifxMessageUtil.increaseDecreasePercentType(org.eclipse.smarthome.binding.lifx.internal.util.LifxMessageUtil.increaseDecreasePercentType)

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