Update error handling in update coordinator (#32452)

This commit is contained in:
Paulus Schoutsen 2020-03-04 08:05:46 -08:00 committed by GitHub
parent f62322cfb4
commit b27c46750c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 58 additions and 67 deletions

View file

@ -5,6 +5,8 @@ import logging
from time import monotonic
from typing import Any, Awaitable, Callable, List, Optional
import aiohttp
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
from homeassistant.helpers.event import async_track_point_in_utc_time
from homeassistant.util.dt import utcnow
@ -114,6 +116,16 @@ class DataUpdateCoordinator:
start = monotonic()
self.data = await self.update_method()
except asyncio.TimeoutError:
if self.last_update_success:
self.logger.error("Timeout fetching %s data", self.name)
self.last_update_success = False
except aiohttp.ClientError as err:
if self.last_update_success:
self.logger.error("Error requesting %s data: %s", self.name, err)
self.last_update_success = False
except UpdateFailed as err:
if self.last_update_success:
self.logger.error("Error fetching %s data: %s", self.name, err)