mirror of
https://github.com/home-assistant/developers.home-assistant.git
synced 2025-07-09 10:26:30 +00:00
Mention update coordinator handles timeout/client error. (#423)
This commit is contained in:
parent
0a4dd63522
commit
cd8b47e7e2
@ -31,6 +31,8 @@ Home Assistant provides a DataUpdateCoordinator class to help you manage this as
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import async_timeout
|
||||||
|
|
||||||
from homeassistant.helpers import entity
|
from homeassistant.helpers import entity
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
@ -48,9 +50,12 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||||||
so entities can quickly look up their data.
|
so entities can quickly look up their data.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
# Note: asyncio.TimeoutError and aiohttp.ClientError are already
|
||||||
|
# handled by the data update coordinator.
|
||||||
|
async with async_timeout.timeout(10):
|
||||||
return await api.fetch_data()
|
return await api.fetch_data()
|
||||||
except ApiError:
|
except ApiError as err:
|
||||||
raise UpdateFailed
|
raise UpdateFailed(f"Error communicating with API: {err}")
|
||||||
|
|
||||||
coordinator = DataUpdateCoordinator(
|
coordinator = DataUpdateCoordinator(
|
||||||
hass,
|
hass,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user