Skip to content

Commit f169400

Browse files
committed
Refactor tests and code to only support current data format for NL cities
1 parent 661e29a commit f169400

7 files changed

Lines changed: 49 additions & 3114 deletions

File tree

irm_kmi_api/api.py

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ def get_current_weather(self, tz: ZoneInfo) -> CurrentWeatherData:
237237
"""
238238

239239
now_hourly = self._get_now_hourly(tz)
240+
if now_hourly is None:
241+
now_hourly = dict()
240242
uv_index = self._get_uv_index()
241243

242244
try:
@@ -284,11 +286,13 @@ def get_current_weather(self, tz: ZoneInfo) -> CurrentWeatherData:
284286
except (TypeError, ValueError):
285287
wind_bearing = None
286288

289+
day_night = self._api_data.get("obs", {}).get("dayNight", now_hourly.get("dayNight"))
290+
287291
current_weather = CurrentWeatherData(
288292
condition=self._cdt_map.get(
289293
(
290294
self._api_data.get("obs", {}).get("ww"),
291-
self._api_data.get("obs", {}).get("dayNight"),
295+
day_night,
292296
),
293297
None,
294298
),
@@ -300,38 +304,6 @@ def get_current_weather(self, tz: ZoneInfo) -> CurrentWeatherData:
300304
uv_index=uv_index,
301305
)
302306

303-
# TODO this code should not be needed anymore as the 'obs' key does not contain the data anymore as of
304-
# January 2026. It might be removed but test cases and fixtures should be adapted.
305-
if self._api_data.get("country", "") == "NL":
306-
if self._api_data.get("obs", {}).get("windSpeedKm") is not None:
307-
current_weather["wind_speed"] = self._api_data.get("obs", {}).get(
308-
"windSpeedKm"
309-
)
310-
if (
311-
self._api_data.get("obs", {}).get("windDirectionText", {}).get("en")
312-
== "VAR"
313-
):
314-
current_weather["wind_bearing"] = None
315-
else:
316-
try:
317-
current_weather["wind_bearing"] = (
318-
float(self._api_data.get("obs", {}).get(
319-
"windDirection")) + 180
320-
) % 360
321-
except (TypeError, ValueError):
322-
pass
323-
324-
# Since June 2024, the NL weather does not include the condition in the 'ww' key, so we get it from the current
325-
# hourly forecast instead if it is missing
326-
# In January 2026, the 'ww' key is back in the observation so this code should not run anymore
327-
if current_weather["condition"] is None:
328-
try:
329-
current_weather["condition"] = self._cdt_map.get(
330-
(int(now_hourly.get("ww")), now_hourly.get("dayNight")), None
331-
)
332-
except (TypeError, ValueError, AttributeError):
333-
current_weather["condition"] = None
334-
335307
return current_weather
336308

337309
def get_radar_forecast(self) -> List[RadarForecast]:
File renamed without changes.

0 commit comments

Comments
 (0)