Skip to content

Commit d2db2b3

Browse files
authored
Merge pull request #142 from golles/132-intermittent-false-snowy-state
Fix: Warm snow bug
2 parents 19721ba + 1af727c commit d2db2b3

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

custom_components/knmi/weather.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,14 @@ def map_condition(self, value: str | None) -> str | None:
119119
@property
120120
def condition(self) -> str | None:
121121
"""Return the current condition."""
122-
return self.map_condition(self.coordinator.get_value(["liveweer", 0, "image"]))
122+
condition = self.map_condition(
123+
self.coordinator.get_value(["liveweer", 0, "image"])
124+
)
125+
126+
if condition == ATTR_CONDITION_SNOWY and self.native_temperature > 6:
127+
condition = ATTR_CONDITION_RAINY
128+
129+
return condition
123130

124131
@property
125132
def native_temperature(self) -> float | None:

tests/fixtures/cold_snow.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"liveweer": [
3+
{
4+
"temp": 6,
5+
"image": "sneeuw"
6+
}
7+
]
8+
}

tests/fixtures/warm_snow.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"liveweer": [
3+
{
4+
"temp": 10.5,
5+
"image": "sneeuw"
6+
}
7+
]
8+
}

tests/test_weather.py

+24
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,27 @@ async def test_async_forecast_twice_daily(hass: HomeAssistant, mocked_data):
259259

260260
assert await config_entry.async_unload(hass)
261261
await hass.async_block_till_done()
262+
263+
264+
@pytest.mark.fixture("warm_snow.json")
265+
async def test_warm_snow_fix(hass: HomeAssistant, mocked_data):
266+
"""Test if we return rainy if the API returns snowy and a temp higher than 6."""
267+
config_entry = await setup_component(hass)
268+
269+
state = hass.states.get("weather.knmi_home")
270+
assert state.state == ATTR_CONDITION_RAINY
271+
272+
assert await config_entry.async_unload(hass)
273+
await hass.async_block_till_done()
274+
275+
276+
@pytest.mark.fixture("cold_snow.json")
277+
async def test_real_snow(hass: HomeAssistant, mocked_data):
278+
"""Test if we return snowy if the API returns snowy and a temp lower than 6."""
279+
config_entry = await setup_component(hass)
280+
281+
state = hass.states.get("weather.knmi_home")
282+
assert state.state == ATTR_CONDITION_SNOWY
283+
284+
assert await config_entry.async_unload(hass)
285+
await hass.async_block_till_done()

0 commit comments

Comments
 (0)