mirror of
https://github.com/skoelle/wt32sc01-dashboard.git
synced 2026-09-17 17:30:25 +00:00
willRainSoon from API
This commit is contained in:
+1
-11
@@ -28,17 +28,7 @@ WeatherData fetchWeather() {
|
||||
fe.precipitationType = precip["type"] | "";
|
||||
data.forecast.push_back(fe);
|
||||
}
|
||||
data.willRainSoon = doc["willRainSoon"] | false;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -35,7 +35,7 @@ void updateRainWarning(const WeatherData &w, bool ok) {
|
||||
lv_obj_del(rainWarningIcon);
|
||||
rainWarningIcon = nullptr;
|
||||
}
|
||||
if (ok && willRainSoon(w, 8)) {
|
||||
if (ok && w.willRainSoon) {
|
||||
rainWarningIcon = Icons::createRainWarning(weatherTile.btn, 28);
|
||||
lv_obj_align(rainWarningIcon, LV_ALIGN_TOP_RIGHT, -4, 4);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user