Phase 0/2: API layer kept 1:1, only secrets.h include path fixed

http_client/weather_api/calendar_api/departures_api are hardware-
independent (HTTP GET + ArduinoJson parsing, same endpoints, same
JSON). Kept verbatim per PLAN.md migration strategy; only changed
#include "../../include/secrets.h" -> #include <secrets.h> to match
the PlatformIO include/ layout (no functional change).
This commit is contained in:
2026-08-02 10:28:56 +02:00
parent abb5c62f3b
commit 59198284fd
8 changed files with 204 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
#include "weather_api.h"
#include "http_client.h"
#include <secrets.h>
#include <ArduinoJson.h>
WeatherData fetchWeather() {
WeatherData data;
ApiResult res = httpGet(WEATHER_API_URL);
if (!res.success) { data.valid = false; return data; }
DynamicJsonDocument doc(8192);
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"] | "";
data.current.description = current["description"] | "";
JsonArray forecast = doc["forecast"];
for (JsonObject entry : forecast) {
ForecastEntry fe;
fe.time = entry["time"] | "";
fe.temperature = entry["temperature"] | 0;
fe.symbol = entry["symbol"] | "";
fe.description = entry["description"] | "";
JsonObject precip = entry["precipitation"];
fe.precipitationProbability = precip["probability"] | 0.0f;
fe.precipitationType = precip["type"] | "";
data.forecast.push_back(fe);
}
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;
}