mirror of
https://github.com/skoelle/m5stack-dashboard.git
synced 2026-09-18 00:50:24 +00:00
willRainSoon from weather API
This commit is contained in:
+5
-11
@@ -11,6 +11,11 @@ WeatherData fetchWeather() {
|
|||||||
DynamicJsonDocument doc(8192);
|
DynamicJsonDocument doc(8192);
|
||||||
if (deserializeJson(doc, res.body)) { data.valid = false; return data; }
|
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"];
|
JsonObject current = doc["current"];
|
||||||
data.current.temperature = current["temperature"] | 0;
|
data.current.temperature = current["temperature"] | 0;
|
||||||
data.current.symbol = current["symbol"] | "";
|
data.current.symbol = current["symbol"] | "";
|
||||||
@@ -31,14 +36,3 @@ WeatherData fetchWeather() {
|
|||||||
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);
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ void renderHomeScreen(bool forceRefresh) {
|
|||||||
M5.Lcd.setCursor(90, 65);
|
M5.Lcd.setCursor(90, 65);
|
||||||
M5.Lcd.print(sanitizeGermanText(lastWeather.current.description));
|
M5.Lcd.print(sanitizeGermanText(lastWeather.current.description));
|
||||||
|
|
||||||
if (willRainSoon(lastWeather, 8)) {
|
if (lastWeather.willRainSoon) {
|
||||||
Icons::drawRainWarning(280, 30);
|
Icons::drawRainWarning(280, 30);
|
||||||
M5.Lcd.setTextColor(Theme::ACCENT_RAIN, Theme::BG);
|
M5.Lcd.setTextColor(Theme::ACCENT_RAIN, Theme::BG);
|
||||||
M5.Lcd.setTextSize(1);
|
M5.Lcd.setTextSize(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user