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:
|
if url == self._last_url and self._limit_refetch:
|
||||||
return self._last_image
|
return self._last_image
|
||||||
|
|
||||||
# aiohttp don't support DigestAuth jet
|
# aiohttp don't support DigestAuth yet
|
||||||
if self._authentication == HTTP_DIGEST_AUTHENTICATION:
|
if self._authentication == HTTP_DIGEST_AUTHENTICATION:
|
||||||
def fetch():
|
def fetch():
|
||||||
"""Read image from a URL."""
|
"""Read image from a URL."""
|
||||||
|
@ -109,15 +109,17 @@ class GenericCamera(Camera):
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
with async_timeout.timeout(10, loop=self.hass.loop):
|
with async_timeout.timeout(10, loop=self.hass.loop):
|
||||||
respone = yield from self.hass.websession.get(
|
response = yield from self.hass.websession.get(
|
||||||
url,
|
url, auth=self._auth)
|
||||||
auth=self._auth
|
self._last_image = yield from response.read()
|
||||||
)
|
yield from response.release()
|
||||||
self._last_image = yield from respone.read()
|
|
||||||
yield from respone.release()
|
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
_LOGGER.error('Timeout getting camera image')
|
_LOGGER.error('Timeout getting camera image')
|
||||||
return self._last_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
|
self._last_url = url
|
||||||
return self._last_image
|
return self._last_image
|
||||||
|
|
|
@ -10,7 +10,7 @@ import logging
|
||||||
from xml.parsers.expat import ExpatError
|
from xml.parsers.expat import ExpatError
|
||||||
|
|
||||||
import async_timeout
|
import async_timeout
|
||||||
from aiohttp.web import HTTPException
|
import aiohttp
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
@ -155,11 +155,8 @@ class YrData(object):
|
||||||
return
|
return
|
||||||
text = yield from resp.text()
|
text = yield from resp.text()
|
||||||
self.hass.async_add_job(resp.release())
|
self.hass.async_add_job(resp.release())
|
||||||
except asyncio.TimeoutError as err:
|
except (asyncio.TimeoutError, aiohttp.errors.ClientError,
|
||||||
try_again(err)
|
aiohttp.errors.ClientDisconnectedError) as err:
|
||||||
return
|
|
||||||
except HTTPException as err:
|
|
||||||
resp.close()
|
|
||||||
try_again(err)
|
try_again(err)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue