Skip to content

Commit

Permalink
Merge pull request #142 from golles/132-intermittent-false-snowy-state
Browse files Browse the repository at this point in the history
Fix: Warm snow bug
  • Loading branch information
golles authored Apr 21, 2024
2 parents 19721ba + 1af727c commit d2db2b3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
9 changes: 8 additions & 1 deletion custom_components/knmi/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions tests/fixtures/cold_snow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"liveweer": [
{
"temp": 6,
"image": "sneeuw"
}
]
}
8 changes: 8 additions & 0 deletions tests/fixtures/warm_snow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"liveweer": [
{
"temp": 10.5,
"image": "sneeuw"
}
]
}
24 changes: 24 additions & 0 deletions tests/test_weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,27 @@ 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()


@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()

0 comments on commit d2db2b3

Please sign in to comment.