willRainSoon from weather API

This commit is contained in:
2026-08-02 22:55:30 +02:00
parent 70d3bfba7c
commit 54e9164dc9
3 changed files with 7 additions and 13 deletions
+5 -11
View File
@@ -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;
}
+1 -1
View File
@@ -19,9 +19,9 @@ struct ForecastEntry {
struct WeatherData {
bool valid = false;
bool willRainSoon = false;
WeatherCurrent current;
std::vector<ForecastEntry> forecast;
};
WeatherData fetchWeather();
bool willRainSoon(const WeatherData &data, int hours = 8);
+1 -1
View File
@@ -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);