Mention update coordinator handles timeout/client error. (#423)

This commit is contained in:
Paulus Schoutsen 2020-03-04 08:06:23 -08:00 committed by GitHub
parent 0a4dd63522
commit cd8b47e7e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,6 +31,8 @@ Home Assistant provides a DataUpdateCoordinator class to help you manage this as
from datetime import timedelta
import logging
import async_timeout
from homeassistant.helpers import entity
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
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.
"""
try:
return await api.fetch_data()
except ApiError:
raise UpdateFailed
# 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()
except ApiError as err:
raise UpdateFailed(f"Error communicating with API: {err}")
coordinator = DataUpdateCoordinator(
hass,