Search in sources :

Example 1 with WeatherInfo

use of cyanogenmod.weather.WeatherInfo in project Gadgetbridge by Freeyourgadget.

the class CMWeatherReceiver method onWeatherRequestCompleted.

@Override
public void onWeatherRequestCompleted(int status, WeatherInfo weatherInfo) {
    if (weatherInfo != null) {
        LOG.info("weather: " + weatherInfo.toString());
        WeatherSpec weatherSpec = new WeatherSpec();
        weatherSpec.timestamp = (int) (weatherInfo.getTimestamp() / 1000);
        weatherSpec.location = weatherInfo.getCity();
        if (weatherInfo.getTemperatureUnit() == FAHRENHEIT) {
            weatherSpec.currentTemp = (int) WeatherUtils.fahrenheitToCelsius(weatherInfo.getTemperature()) + 273;
            weatherSpec.todayMaxTemp = (int) WeatherUtils.fahrenheitToCelsius(weatherInfo.getTodaysHigh()) + 273;
            weatherSpec.todayMinTemp = (int) WeatherUtils.fahrenheitToCelsius(weatherInfo.getTodaysLow()) + 273;
        } else {
            weatherSpec.currentTemp = (int) weatherInfo.getTemperature() + 273;
            weatherSpec.todayMaxTemp = (int) weatherInfo.getTodaysHigh() + 273;
            weatherSpec.todayMinTemp = (int) weatherInfo.getTodaysLow() + 273;
        }
        if (weatherInfo.getWindSpeedUnit() == MPH) {
            weatherSpec.windSpeed = (float) weatherInfo.getWindSpeed() * 1.609344f;
        } else {
            weatherSpec.windSpeed = (float) weatherInfo.getWindSpeed();
        }
        weatherSpec.windDirection = (int) weatherInfo.getWindDirection();
        weatherSpec.currentConditionCode = Weather.mapToOpenWeatherMapCondition(CMtoYahooCondintion(weatherInfo.getConditionCode()));
        weatherSpec.currentCondition = Weather.getConditionString(weatherSpec.currentConditionCode);
        weatherSpec.currentHumidity = (int) weatherInfo.getHumidity();
        weatherSpec.forecasts = new ArrayList<>();
        List<WeatherInfo.DayForecast> forecasts = weatherInfo.getForecasts();
        for (int i = 1; i < forecasts.size(); i++) {
            WeatherInfo.DayForecast cmForecast = forecasts.get(i);
            WeatherSpec.Forecast gbForecast = new WeatherSpec.Forecast();
            if (weatherInfo.getTemperatureUnit() == FAHRENHEIT) {
                gbForecast.maxTemp = (int) WeatherUtils.fahrenheitToCelsius(cmForecast.getHigh()) + 273;
                gbForecast.minTemp = (int) WeatherUtils.fahrenheitToCelsius(cmForecast.getLow()) + 273;
            } else {
                gbForecast.maxTemp = (int) cmForecast.getHigh() + 273;
                gbForecast.minTemp = (int) cmForecast.getLow() + 273;
            }
            gbForecast.conditionCode = Weather.mapToOpenWeatherMapCondition(CMtoYahooCondintion(cmForecast.getConditionCode()));
            weatherSpec.forecasts.add(gbForecast);
        }
        Weather.getInstance().setWeatherSpec(weatherSpec);
        GBApplication.deviceService().onSendWeather(weatherSpec);
    } else {
        LOG.info("request has returned null for WeatherInfo");
    }
}
Also used : WeatherInfo(cyanogenmod.weather.WeatherInfo) WeatherSpec(nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec)

Aggregations

WeatherInfo (cyanogenmod.weather.WeatherInfo)1 WeatherSpec (nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec)1