Improve async generic camera's error handling (#4316)
* Handle errors * Feedback * DisconnectedErrorpull/3429/head
parent
e76d553513
commit
9bb94a4512
|
@ -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
|
||||
|
|
|
@ -10,7 +10,7 @@ import logging
|
|||
from xml.parsers.expat import ExpatError
|
||||
|
||||
import async_timeout
|
||||
from aiohttp.web import HTTPException
|
||||
import aiohttp
|
||||
import voluptuous as vol
|
||||
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -155,11 +155,8 @@ class YrData(object):
|
|||
return
|
||||
text = yield from resp.text()
|
||||
self.hass.async_add_job(resp.release())
|
||||
except asyncio.TimeoutError as err:
|
||||
try_again(err)
|
||||
return
|
||||
except HTTPException as err:
|
||||
resp.close()
|
||||
except (asyncio.TimeoutError, aiohttp.errors.ClientError,
|
||||
aiohttp.errors.ClientDisconnectedError) as err:
|
||||
try_again(err)
|
||||
return
|
||||
|
||||
|
|
Loading…
Reference in New Issue