mirror of
https://github.com/skoelle/wt32sc01-dashboard.git
synced 2026-09-18 01:40:24 +00:00
willRainSoon from API
This commit is contained in:
+1
-11
@@ -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;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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);
|
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user