From cd8b47e7e2e808bcfaa2a77de2ae0ddffc84d935 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Wed, 4 Mar 2020 08:06:23 -0800 Subject: [PATCH] Mention update coordinator handles timeout/client error. (#423) --- docs/integration_fetching_data.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/integration_fetching_data.md b/docs/integration_fetching_data.md index c491efd5..0dd47bbe 100644 --- a/docs/integration_fetching_data.md +++ b/docs/integration_fetching_data.md @@ -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,