implement client for meteo weather api

This commit is contained in:
2026-01-10 17:53:22 +01:00
parent 1f439338da
commit 4fb5d9c5f8
8 changed files with 191 additions and 3 deletions
@@ -0,0 +1,41 @@
package SuMoC.backend.meteo;
import java.util.Set;
/**
* Simplified WMO weather codes, taken from https://gist.github.com/stellasphere/9490c195ed2b53c707087c8c2db4ec0c
*/
public enum WeatherCondition {
CLEAR(Set.of(0, 1)),
PARTLY_CLOUDY(Set.of(2)),
CLOUDY(Set.of(3)),
FOG(Set.of(45, 48)),
DRIZZLE(Set.of(51, 53, 55, 56, 57)),
RAIN(Set.of(61, 63, 65, 66, 67)),
SNOW(Set.of(71, 73, 75, 77, 85, 86)),
SHOWERS(Set.of(80, 81, 82)),
THUNDERSTORM(Set.of(95, 96, 99)),
UNKNOWN(Set.of());
private final Set<Integer> codes;
WeatherCondition(Set<Integer> codes) {
this.codes = codes;
}
public static WeatherCondition from(int code) throws Exception {
for (WeatherCondition condition : values()) {
if (condition.codes.contains(code)) {
return condition;
}
}
throw new UnknownWeatherCodeException("Encountered unknown weather code.");
}
}