From 8d2d71c16a20362b81d8d58759fa678ced899bc5 Mon Sep 17 00:00:00 2001 From: Phil Bruckner Date: Thu, 14 Mar 2019 12:56:33 -0500 Subject: [PATCH] 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 --- homeassistant/components/amcrest/__init__.py | 9 ++++----- homeassistant/components/amcrest/camera.py | 8 ++++---- requirements_all.txt | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/amcrest/__init__.py b/homeassistant/components/amcrest/__init__.py index b976c1bd9d3..b11c263c56b 100644 --- a/homeassistant/components/amcrest/__init__.py +++ b/homeassistant/components/amcrest/__init__.py @@ -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: {}
' diff --git a/homeassistant/components/amcrest/camera.py b/homeassistant/components/amcrest/camera.py index f6c507e73f4..32885c2a83c 100644 --- a/homeassistant/components/amcrest/camera.py +++ b/homeassistant/components/amcrest/camera.py @@ -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 diff --git a/requirements_all.txt b/requirements_all.txt index a4967357d51..ca8193045fa 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -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