Bump amcrest to 1.2.6 & use new exceptions (#22040)

* Bump amcrest to 1.2.6 & use new exceptions

* Fix lint failure

* Use AmcrestError instead of individual ones
This commit is contained in:
Phil Bruckner 2019-03-14 12:56:33 -05:00 committed by Paulus Schoutsen
parent 4e84e8a15e
commit 8d2d71c16a
3 changed files with 9 additions and 10 deletions

View File

@ -4,8 +4,6 @@ from datetime import timedelta
import aiohttp
import voluptuous as vol
from requests.exceptions import HTTPError, ConnectTimeout
from requests.exceptions import ConnectionError as ConnectError
from homeassistant.const import (
CONF_NAME, CONF_HOST, CONF_PORT, CONF_USERNAME, CONF_PASSWORD,
@ -13,7 +11,8 @@ from homeassistant.const import (
from homeassistant.helpers import discovery
import homeassistant.helpers.config_validation as cv
REQUIREMENTS = ['amcrest==1.2.5']
REQUIREMENTS = ['amcrest==1.2.6']
DEPENDENCIES = ['ffmpeg']
_LOGGER = logging.getLogger(__name__)
@ -91,7 +90,7 @@ CONFIG_SCHEMA = vol.Schema({
def setup(hass, config):
"""Set up the Amcrest IP Camera component."""
from amcrest import AmcrestCamera
from amcrest import AmcrestCamera, AmcrestError
hass.data[DATA_AMCREST] = {}
amcrest_cams = config[DOMAIN]
@ -105,7 +104,7 @@ def setup(hass, config):
# pylint: disable=pointless-statement
camera.current_time
except (ConnectError, ConnectTimeout, HTTPError) as ex:
except AmcrestError as ex:
_LOGGER.error("Unable to connect to Amcrest camera: %s", str(ex))
hass.components.persistent_notification.create(
'Error: {}<br />'

View File

@ -2,9 +2,6 @@
import asyncio
import logging
from requests import RequestException
from urllib3.exceptions import ReadTimeoutError
from homeassistant.components.amcrest import (
DATA_AMCREST, STREAM_SOURCE_LIST, TIMEOUT)
from homeassistant.components.camera import Camera
@ -14,6 +11,7 @@ from homeassistant.helpers.aiohttp_client import (
async_get_clientsession, async_aiohttp_proxy_web,
async_aiohttp_proxy_stream)
DEPENDENCIES = ['amcrest', 'ffmpeg']
_LOGGER = logging.getLogger(__name__)
@ -51,13 +49,15 @@ class AmcrestCam(Camera):
async def async_camera_image(self):
"""Return a still image response from the camera."""
from amcrest import AmcrestError
async with self._snapshot_lock:
try:
# Send the request to snap a picture and return raw jpg data
response = await self.hass.async_add_executor_job(
self._camera.snapshot, self._resolution)
return response.data
except (RequestException, ReadTimeoutError, ValueError) as error:
except AmcrestError as error:
_LOGGER.error(
'Could not get camera image due to error %s', error)
return None

View File

@ -155,7 +155,7 @@ alarmdecoder==1.13.2
alpha_vantage==2.1.0
# homeassistant.components.amcrest
amcrest==1.2.5
amcrest==1.2.6
# homeassistant.components.androidtv.media_player
androidtv==0.0.11