Improve async generic camera's error handling (#4316)
* Handle errors * Feedback * DisconnectedError
This commit is contained in:
parent
e76d553513
commit
9bb94a4512
2 changed files with 12 additions and 13 deletions
|
@ -91,7 +91,7 @@ class GenericCamera(Camera):
|
|||
if url == self._last_url and self._limit_refetch:
|
||||
return self._last_image
|
||||
|
||||
# aiohttp don't support DigestAuth jet
|
||||
# aiohttp don't support DigestAuth yet
|
||||
if self._authentication == HTTP_DIGEST_AUTHENTICATION:
|
||||
def fetch():
|
||||
"""Read image from a URL."""
|
||||
|
@ -109,15 +109,17 @@ class GenericCamera(Camera):
|
|||
else:
|
||||
try:
|
||||
with async_timeout.timeout(10, loop=self.hass.loop):
|
||||
respone = yield from self.hass.websession.get(
|
||||
url,
|
||||
auth=self._auth
|
||||
)
|
||||
self._last_image = yield from respone.read()
|
||||
yield from respone.release()
|
||||
response = yield from self.hass.websession.get(
|
||||
url, auth=self._auth)
|
||||
self._last_image = yield from response.read()
|
||||
yield from response.release()
|
||||
except asyncio.TimeoutError:
|
||||
_LOGGER.error('Timeout getting camera image')
|
||||
return self._last_image
|
||||
except (aiohttp.errors.ClientError,
|
||||
aiohttp.errors.ClientDisconnectedError) as err:
|
||||
_LOGGER.error('Error getting new camera image: %s', err)
|
||||
return self._last_image
|
||||
|
||||
self._last_url = url
|
||||
return self._last_image
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue