Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Warm snow bug #142

Merged
merged 4 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()