From 2fb9d660c8fc8703ff7ba6fd5b67493d4267651f Mon Sep 17 00:00:00 2001 From: Sander Date: Sat, 25 May 2024 13:54:25 +0000 Subject: [PATCH] Handle possible unavailable conditions --- custom_components/knmi/weather.py | 3 +++ tests/test_weather.py | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/custom_components/knmi/weather.py b/custom_components/knmi/weather.py index 80f763d..31d05f6 100644 --- a/custom_components/knmi/weather.py +++ b/custom_components/knmi/weather.py @@ -61,6 +61,9 @@ "nachtbewolkt": ATTR_CONDITION_CLOUDY, # TODO: Check with the supplier why this is still in the response while not in the docs. "wolkennacht": ATTR_CONDITION_CLOUDY, + # Possible unavailable conditions. + "-": None, + "_": None, } diff --git a/tests/test_weather.py b/tests/test_weather.py index e00eaa1..0b1a587 100644 --- a/tests/test_weather.py +++ b/tests/test_weather.py @@ -63,10 +63,15 @@ async def test_map_conditions(hass: HomeAssistant, mocked_data, caplog): assert weather.map_condition("nachtmist") == ATTR_CONDITION_FOG assert weather.map_condition("helderenacht") == ATTR_CONDITION_CLEAR_NIGHT assert weather.map_condition("nachtbewolkt") == ATTR_CONDITION_CLOUDY + assert weather.map_condition("nachtbewolkt") == ATTR_CONDITION_CLOUDY - # # Undocumented conditions. + # Undocumented conditions. assert weather.map_condition("wolkennacht") == ATTR_CONDITION_CLOUDY + # Possible unavailable conditions. + assert weather.map_condition("-") == None + assert weather.map_condition("_") == None + # Error cases. assert weather.map_condition(None) is None assert (