willRainSoon from API

This commit is contained in:
2026-08-02 22:51:39 +02:00
parent 0fec1ecfac
commit 4a4e897e66
3 changed files with 3 additions and 13 deletions
+1 -11
View File
@@ -28,17 +28,7 @@ WeatherData fetchWeather() {
fe.precipitationType = precip["type"] | ""; fe.precipitationType = precip["type"] | "";
data.forecast.push_back(fe); data.forecast.push_back(fe);
} }
data.willRainSoon = doc["willRainSoon"] | false;
data.valid = true; data.valid = true;
return data; 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 { struct WeatherData {
bool valid = false; bool valid = false;
bool willRainSoon = false;
WeatherCurrent current; WeatherCurrent current;
std::vector<ForecastEntry> forecast; std::vector<ForecastEntry> forecast;
}; };
WeatherData fetchWeather(); WeatherData fetchWeather();
bool willRainSoon(const WeatherData &data, int hours = 8);
+1 -1
View File
@@ -35,7 +35,7 @@ void updateRainWarning(const WeatherData &w, bool ok) {
lv_obj_del(rainWarningIcon); lv_obj_del(rainWarningIcon);
rainWarningIcon = nullptr; rainWarningIcon = nullptr;
} }
if (ok && willRainSoon(w, 8)) { if (ok && w.willRainSoon) {
rainWarningIcon = Icons::createRainWarning(weatherTile.btn, 28); rainWarningIcon = Icons::createRainWarning(weatherTile.btn, 28);
lv_obj_align(rainWarningIcon, LV_ALIGN_TOP_RIGHT, -4, 4); lv_obj_align(rainWarningIcon, LV_ALIGN_TOP_RIGHT, -4, 4);
} }