Search in sources :

Example 16 with DateTimeType

use of org.eclipse.smarthome.core.library.types.DateTimeType in project smarthome by eclipse.

the class WeatherUndergroundHandler method updateCurrentObservationChannel.

private State updateCurrentObservationChannel(String channelId, WeatherUndergroundJsonCurrent current) {
    WUQuantity quantity;
    String channelTypeId = getChannelTypeId(channelId);
    switch(channelTypeId) {
        case "location":
            return undefOrState(current.getLocation(), new StringType(current.getLocation()));
        case "stationId":
            return undefOrState(current.getStationId(), new StringType(current.getStationId()));
        case "observationTime":
            return undefOrState(current.getObservationTime(), new DateTimeType(current.getObservationTime()));
        case "conditions":
            return undefOrState(current.getConditions(), new StringType(current.getConditions()));
        case "temperature":
            quantity = getTemperature(current.getTemperatureC(), current.getTemperatureF());
            return undefOrQuantity(quantity);
        case "relativeHumidity":
            return undefOrState(current.getRelativeHumidity(), new QuantityType<>(current.getRelativeHumidity(), SmartHomeUnits.PERCENT));
        case "windDirection":
            return undefOrState(current.getWindDirection(), new StringType(current.getWindDirection()));
        case "windDirectionDegrees":
            return undefOrState(current.getWindDirectionDegrees(), new QuantityType<>(current.getWindDirectionDegrees(), SmartHomeUnits.DEGREE_ANGLE));
        case "windSpeed":
            quantity = getSpeed(current.getWindSpeedKmh(), current.getWindSpeedMph());
            return undefOrQuantity(quantity);
        case "windGust":
            quantity = getSpeed(current.getWindGustKmh(), current.getWindGustMph());
            return undefOrQuantity(quantity);
        case "pressure":
            quantity = getPressure(current.getPressureHPa(), current.getPressureInHg());
            return undefOrQuantity(quantity);
        case "pressureTrend":
            return undefOrState(current.getPressureTrend(), new StringType(current.getPressureTrend()));
        case "dewPoint":
            quantity = getTemperature(current.getDewPointC(), current.getDewPointF());
            return undefOrQuantity(quantity);
        case "heatIndex":
            quantity = getTemperature(current.getHeatIndexC(), current.getHeatIndexF());
            return undefOrQuantity(quantity);
        case "windChill":
            quantity = getTemperature(current.getWindChillC(), current.getWindChillF());
            return undefOrQuantity(quantity);
        case "feelingTemperature":
            quantity = getTemperature(current.getFeelingTemperatureC(), current.getFeelingTemperatureF());
            return undefOrQuantity(quantity);
        case "visibility":
            quantity = getWUQuantity(KILO(SIUnits.METRE), ImperialUnits.MILE, current.getVisibilityKm(), current.getVisibilityMi());
            return undefOrQuantity(quantity);
        case "solarRadiation":
            return undefOrQuantity(new WUQuantity(current.getSolarRadiation(), SmartHomeUnits.IRRADIANCE));
        case "UVIndex":
            return undefOrDecimal(current.getUVIndex());
        case "precipitationDay":
            quantity = getPrecipitation(current.getPrecipitationDayMm(), current.getPrecipitationDayIn());
            return undefOrQuantity(quantity);
        case "precipitationHour":
            quantity = getPrecipitation(current.getPrecipitationHourMm(), current.getPrecipitationHourIn());
            return undefOrQuantity(quantity);
        case "iconKey":
            return undefOrState(current.getIconKey(), new StringType(current.getIconKey()));
        case "icon":
            State icon = HttpUtil.downloadImage(current.getIcon().toExternalForm());
            if (icon == null) {
                logger.debug("Failed to download the content of URL {}", current.getIcon().toExternalForm());
                return null;
            }
            return icon;
        default:
            return null;
    }
}
Also used : DateTimeType(org.eclipse.smarthome.core.library.types.DateTimeType) StringType(org.eclipse.smarthome.core.library.types.StringType) State(org.eclipse.smarthome.core.types.State)

Aggregations

DateTimeType (org.eclipse.smarthome.core.library.types.DateTimeType)16 Test (org.junit.Test)10 ZonedDateTime (java.time.ZonedDateTime)7 State (org.eclipse.smarthome.core.types.State)6 ZoneOffset (java.time.ZoneOffset)4 Configuration (org.eclipse.smarthome.config.core.Configuration)4 StringType (org.eclipse.smarthome.core.library.types.StringType)4 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 Ignore (org.junit.Ignore)3 Item (org.eclipse.smarthome.core.items.Item)2 ColorItem (org.eclipse.smarthome.core.library.items.ColorItem)2 DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)2 Widget (org.eclipse.smarthome.model.sitemap.Widget)2 BigDecimal (java.math.BigDecimal)1 LinkedList (java.util.LinkedList)1 Temperature (javax.measure.quantity.Temperature)1 WeatherUndergroundJsonForecastDay (org.eclipse.smarthome.binding.weatherunderground.internal.json.WeatherUndergroundJsonForecastDay)1 HSBType (org.eclipse.smarthome.core.library.types.HSBType)1 OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)1