mirror of
https://github.com/home-assistant/core.git
synced 2025-04-19 14:57:52 +00:00
Handle timeouts on AEMET init (#102289)
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
This commit is contained in:
parent
d00934a8f8
commit
7ec2496c81
@ -1,5 +1,6 @@
|
||||
"""The AEMET OpenData component."""
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
from aemet_opendata.exceptions import TownNotFound
|
||||
@ -8,6 +9,7 @@ from aemet_opendata.interface import AEMET, ConnectionOptions
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers import aiohttp_client
|
||||
|
||||
from .const import (
|
||||
@ -37,6 +39,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
except TownNotFound as err:
|
||||
_LOGGER.error(err)
|
||||
return False
|
||||
except asyncio.TimeoutError as err:
|
||||
raise ConfigEntryNotReady("AEMET OpenData API timed out") from err
|
||||
|
||||
weather_coordinator = WeatherUpdateCoordinator(hass, aemet)
|
||||
await weather_coordinator.async_config_entry_first_refresh()
|
||||
|
@ -1,4 +1,5 @@
|
||||
"""Define tests for the AEMET OpenData init."""
|
||||
import asyncio
|
||||
from unittest.mock import patch
|
||||
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
@ -70,3 +71,29 @@ async def test_init_town_not_found(
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id) is False
|
||||
|
||||
|
||||
async def test_init_api_timeout(
|
||||
hass: HomeAssistant,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
) -> None:
|
||||
"""Test API timeouts when loading the AEMET integration."""
|
||||
|
||||
hass.config.set_time_zone("UTC")
|
||||
freezer.move_to("2021-01-09 12:00:00+00:00")
|
||||
with patch(
|
||||
"homeassistant.components.aemet.AEMET.api_call",
|
||||
side_effect=asyncio.TimeoutError,
|
||||
):
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={
|
||||
CONF_API_KEY: "api-key",
|
||||
CONF_LATITUDE: "0.0",
|
||||
CONF_LONGITUDE: "0.0",
|
||||
CONF_NAME: "AEMET",
|
||||
},
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id) is False
|
||||
|
Loading…
x
Reference in New Issue
Block a user