Skip to content

Commit

Permalink
Make openweathermap show rain and snow data (indilib#2068)
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-englmaier authored May 30, 2024
1 parent ab21178 commit 824f83f
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions drivers/weather/openweathermap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,30 @@ IPState OpenWeatherMap::updateWeather()
weatherReport["wind"]["speed"].get_to(wind);
// Cloud
weatherReport["clouds"]["all"].get_to(clouds);
try
// Rain (does not exist in all reports)
if (weatherReport.contains("rain"))
{
// Rain
weatherReport["rain"]["h"].get_to(rain);
// Snow
weatherReport["snow"]["h"].get_to(snow);
if (weatherReport["rain"].contains("h"))
{
weatherReport["rain"]["h"].get_to(rain);
}
else if (weatherReport["rain"].contains("1h"))
{
weatherReport["rain"]["1h"].get_to(rain);
}
}
// Snow (does not exist in all reports)
if (weatherReport.contains("snow"))
{
if (weatherReport["snow"].contains("h"))
{
weatherReport["snow"]["h"].get_to(snow);
}
else if (weatherReport["snow"].contains("1h"))
{
weatherReport["snow"]["1h"].get_to(snow);
}
}
// Ignore error since these values do not exist in all reports.
catch (json::exception &e) {}

}
catch (json::exception &e)
Expand Down

0 comments on commit 824f83f

Please sign in to comment.