Skip to content

Commit

Permalink
Add test_async_update_forecast_fail
Browse files Browse the repository at this point in the history
  • Loading branch information
Limych committed May 8, 2024
1 parent f286474 commit 23b16da
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion tests/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
CONF_PLATFORM,
UnitOfTemperature,
)
from homeassistant.core import HomeAssistant, State
from homeassistant.core import HomeAssistant, State, SupportsResponse
from homeassistant.exceptions import HomeAssistantError
from homeassistant.util import dt as dt_util

Expand Down Expand Up @@ -184,3 +184,35 @@ async def test_async_update(hass: HomeAssistant, default_sensor):
assert default_sensor.available
assert default_sensor.is_on is False
assert default_sensor.icon == ICON_SUMMER


async def test_async_update_forecast_fail(hass: HomeAssistant, default_sensor):
"""Test sensor update on forecast fail."""
hass.states._states[MOCK_WEATHER_ENTITY] = State(MOCK_WEATHER_ENTITY, None)

with raises(HomeAssistantError):
await default_sensor.async_update()

hass.states.async_set(MOCK_WEATHER_ENTITY, "State")

with raises(HomeAssistantError):
await default_sensor.async_update()

async_mock_service(
hass,
CONF_WEATHER,
SERVICE_GET_FORECASTS,
supports_response=SupportsResponse.OPTIONAL,
)

hass.states.async_set(
MOCK_WEATHER_ENTITY,
"State",
attributes={
ATTR_WEATHER_TEMPERATURE: -1,
ATTR_SUPPORTED_FEATURES: WeatherEntityFeature.FORECAST_DAILY,
},
)

with raises(HomeAssistantError):
await default_sensor.async_update()

0 comments on commit 23b16da

Please sign in to comment.