Search in sources :

Example 1 with WeatherUndergroundJsonForecastDay

use of org.eclipse.smarthome.binding.weatherunderground.internal.json.WeatherUndergroundJsonForecastDay in project smarthome by eclipse.

the class WeatherUndergroundHandler method updateForecastChannel.

private State updateForecastChannel(String channelId, WeatherUndergroundJsonForecast forecast) {
    WUQuantity quantity;
    int day = getDay(channelId);
    WeatherUndergroundJsonForecastDay dayForecast = forecast.getSimpleForecast(day);
    String channelTypeId = getChannelTypeId(channelId);
    switch(channelTypeId) {
        case "forecastTime":
            return undefOrState(dayForecast.getForecastTime(), new DateTimeType(dayForecast.getForecastTime()));
        case "conditions":
            return undefOrState(dayForecast.getConditions(), new StringType(dayForecast.getConditions()));
        case "minTemperature":
            quantity = getTemperature(dayForecast.getMinTemperatureC(), dayForecast.getMinTemperatureF());
            return undefOrQuantity(quantity);
        case "maxTemperature":
            quantity = getTemperature(dayForecast.getMaxTemperatureC(), dayForecast.getMaxTemperatureF());
            return undefOrQuantity(quantity);
        case "relativeHumidity":
            return undefOrState(dayForecast.getRelativeHumidity(), new QuantityType<>(dayForecast.getRelativeHumidity(), SmartHomeUnits.PERCENT));
        case "probaPrecipitation":
            return undefOrState(dayForecast.getProbaPrecipitation(), new QuantityType<>(dayForecast.getProbaPrecipitation(), SmartHomeUnits.PERCENT));
        case "precipitationDay":
            quantity = getPrecipitation(dayForecast.getPrecipitationDayMm(), dayForecast.getPrecipitationDayIn());
            return undefOrQuantity(quantity);
        case "snow":
            quantity = getWUQuantity(CENTI(SIUnits.METRE), ImperialUnits.INCH, dayForecast.getSnowCm(), dayForecast.getSnowIn());
            return undefOrQuantity(quantity);
        case "maxWindDirection":
            return undefOrState(dayForecast.getMaxWindDirection(), new StringType(dayForecast.getMaxWindDirection()));
        case "maxWindDirectionDegrees":
            return undefOrState(dayForecast.getMaxWindDirectionDegrees(), new QuantityType<>(dayForecast.getMaxWindDirectionDegrees(), SmartHomeUnits.DEGREE_ANGLE));
        case "maxWindSpeed":
            quantity = getSpeed(dayForecast.getMaxWindSpeedKmh(), dayForecast.getMaxWindSpeedMph());
            return undefOrQuantity(quantity);
        case "averageWindDirection":
            return undefOrState(dayForecast.getAverageWindDirection(), new StringType(dayForecast.getAverageWindDirection()));
        case "averageWindDirectionDegrees":
            return undefOrState(dayForecast.getAverageWindDirectionDegrees(), new QuantityType<>(dayForecast.getAverageWindDirectionDegrees(), SmartHomeUnits.DEGREE_ANGLE));
        case "averageWindSpeed":
            quantity = getSpeed(dayForecast.getAverageWindSpeedKmh(), dayForecast.getAverageWindSpeedMph());
            return undefOrQuantity(quantity);
        case "iconKey":
            return undefOrState(dayForecast.getIconKey(), new StringType(dayForecast.getIconKey()));
        case "icon":
            State icon = HttpUtil.downloadImage(dayForecast.getIcon().toExternalForm());
            if (icon == null) {
                logger.debug("Failed to download the content of URL {}", dayForecast.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) WeatherUndergroundJsonForecastDay(org.eclipse.smarthome.binding.weatherunderground.internal.json.WeatherUndergroundJsonForecastDay)

Aggregations

WeatherUndergroundJsonForecastDay (org.eclipse.smarthome.binding.weatherunderground.internal.json.WeatherUndergroundJsonForecastDay)1 DateTimeType (org.eclipse.smarthome.core.library.types.DateTimeType)1 StringType (org.eclipse.smarthome.core.library.types.StringType)1 State (org.eclipse.smarthome.core.types.State)1