Skip to content

Commit

Permalink
Handle possible unavailable conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
golles committed May 25, 2024
1 parent c86107c commit 2fb9d66
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions custom_components/knmi/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}


Expand Down
7 changes: 6 additions & 1 deletion tests/test_weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 2fb9d66

Please sign in to comment.