From 54e9164dc9832415959318cc04238f2768e59541 Mon Sep 17 00:00:00 2001 From: Stefan Koelle Date: Sun, 2 Aug 2026 22:55:30 +0200 Subject: [PATCH] willRainSoon from weather API --- src/api/weather_api.cpp | 16 +++++----------- src/api/weather_api.h | 2 +- src/screens/home_screen.cpp | 2 +- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/api/weather_api.cpp b/src/api/weather_api.cpp index 34989b2..a27b16a 100644 --- a/src/api/weather_api.cpp +++ b/src/api/weather_api.cpp @@ -11,6 +11,11 @@ WeatherData fetchWeather() { DynamicJsonDocument doc(8192); if (deserializeJson(doc, res.body)) { data.valid = false; return data; } + data.willRainSoon = doc["willRainSoon"] | false; + + JsonObject current = doc["current"]; + if (deserializeJson(doc, res.body)) { data.valid = false; return data; } + JsonObject current = doc["current"]; data.current.temperature = current["temperature"] | 0; data.current.symbol = current["symbol"] | ""; @@ -31,14 +36,3 @@ WeatherData fetchWeather() { data.valid = true; return data; } - -bool willRainSoon(const WeatherData &data, int hours) { - if (!data.valid) return false; - int checked = 0; - for (const auto &entry : data.forecast) { - if (checked >= hours) break; - if (entry.precipitationType == "rain" && entry.precipitationProbability > 0.0f) return true; - checked++; - } - return false; -} diff --git a/src/api/weather_api.h b/src/api/weather_api.h index 73cf32e..464b5db 100644 --- a/src/api/weather_api.h +++ b/src/api/weather_api.h @@ -19,9 +19,9 @@ struct ForecastEntry { struct WeatherData { bool valid = false; + bool willRainSoon = false; WeatherCurrent current; std::vector forecast; }; WeatherData fetchWeather(); -bool willRainSoon(const WeatherData &data, int hours = 8); diff --git a/src/screens/home_screen.cpp b/src/screens/home_screen.cpp index 960b25c..5c9c97b 100644 --- a/src/screens/home_screen.cpp +++ b/src/screens/home_screen.cpp @@ -57,7 +57,7 @@ void renderHomeScreen(bool forceRefresh) { M5.Lcd.setCursor(90, 65); M5.Lcd.print(sanitizeGermanText(lastWeather.current.description)); - if (willRainSoon(lastWeather, 8)) { + if (lastWeather.willRainSoon) { Icons::drawRainWarning(280, 30); M5.Lcd.setTextColor(Theme::ACCENT_RAIN, Theme::BG); M5.Lcd.setTextSize(1);