From 8341be00b57eedf7317e00b062d005c0c03baf42 Mon Sep 17 00:00:00 2001 From: Sander Date: Fri, 19 Apr 2024 17:11:15 +0000 Subject: [PATCH 1/2] Fix: Warm snow bug --- custom_components/knmi/weather.py | 9 ++++++++- tests/fixtures/warm_snow.json | 8 ++++++++ tests/test_weather.py | 12 ++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/warm_snow.json diff --git a/custom_components/knmi/weather.py b/custom_components/knmi/weather.py index f8f6e6c..723b434 100644 --- a/custom_components/knmi/weather.py +++ b/custom_components/knmi/weather.py @@ -119,7 +119,14 @@ def map_condition(self, value: str | None) -> str | None: @property def condition(self) -> str | None: """Return the current condition.""" - return self.map_condition(self.coordinator.get_value(["liveweer", 0, "image"])) + condition = self.map_condition( + self.coordinator.get_value(["liveweer", 0, "image"]) + ) + + if condition == ATTR_CONDITION_SNOWY and self.native_temperature > 6: + condition = ATTR_CONDITION_RAINY + + return condition @property def native_temperature(self) -> float | None: diff --git a/tests/fixtures/warm_snow.json b/tests/fixtures/warm_snow.json new file mode 100644 index 0000000..1bbef8f --- /dev/null +++ b/tests/fixtures/warm_snow.json @@ -0,0 +1,8 @@ +{ + "liveweer": [ + { + "temp": 10.5, + "image": "sneeuw" + } + ] +} diff --git a/tests/test_weather.py b/tests/test_weather.py index 4a99ef8..3bc642a 100644 --- a/tests/test_weather.py +++ b/tests/test_weather.py @@ -259,3 +259,15 @@ async def test_async_forecast_twice_daily(hass: HomeAssistant, mocked_data): assert await config_entry.async_unload(hass) await hass.async_block_till_done() + + +@pytest.mark.fixture("warm_snow.json") +async def test_warm_snow_fix(hass: HomeAssistant, mocked_data): + """Test if we return rainy if the API returns snowy and a temp higher than 6.""" + config_entry = await setup_component(hass) + + state = hass.states.get("weather.knmi_home") + assert state.state == ATTR_CONDITION_RAINY + + assert await config_entry.async_unload(hass) + await hass.async_block_till_done() From 0a12f85b6e58b0e0add0e9d0961932b8c2af26ab Mon Sep 17 00:00:00 2001 From: Sander Date: Fri, 19 Apr 2024 17:26:45 +0000 Subject: [PATCH 2/2] Add test case for real sow --- tests/fixtures/cold_snow.json | 8 ++++++++ tests/test_weather.py | 12 ++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 tests/fixtures/cold_snow.json diff --git a/tests/fixtures/cold_snow.json b/tests/fixtures/cold_snow.json new file mode 100644 index 0000000..3f5fffe --- /dev/null +++ b/tests/fixtures/cold_snow.json @@ -0,0 +1,8 @@ +{ + "liveweer": [ + { + "temp": 6, + "image": "sneeuw" + } + ] +} diff --git a/tests/test_weather.py b/tests/test_weather.py index 3bc642a..7385b8f 100644 --- a/tests/test_weather.py +++ b/tests/test_weather.py @@ -271,3 +271,15 @@ async def test_warm_snow_fix(hass: HomeAssistant, mocked_data): assert await config_entry.async_unload(hass) await hass.async_block_till_done() + + +@pytest.mark.fixture("cold_snow.json") +async def test_real_snow(hass: HomeAssistant, mocked_data): + """Test if we return snowy if the API returns snowy and a temp lower than 6.""" + config_entry = await setup_component(hass) + + state = hass.states.get("weather.knmi_home") + assert state.state == ATTR_CONDITION_SNOWY + + assert await config_entry.async_unload(hass) + await hass.async_block_till_done()