From 3467020dbf1d4747c07900d8f5fe2c1c0baf5292 Mon Sep 17 00:00:00 2001 From: Marcelo Moreira de Mello Date: Mon, 12 Dec 2016 00:46:19 -0500 Subject: [PATCH] Added resolution support to Amcrest cameras (#4860) * Added resolution support to Amcrest cameras * Ordered alphabetically DEFAULT_ options --- homeassistant/components/camera/amcrest.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/camera/amcrest.py b/homeassistant/components/camera/amcrest.py index 97ed45f21e4..c6568677583 100644 --- a/homeassistant/components/camera/amcrest.py +++ b/homeassistant/components/camera/amcrest.py @@ -18,16 +18,26 @@ REQUIREMENTS = ['amcrest==1.0.0'] _LOGGER = logging.getLogger(__name__) -DEFAULT_PORT = 80 +CONF_RESOLUTION = 'resolution' + DEFAULT_NAME = 'Amcrest Camera' +DEFAULT_PORT = 80 +DEFAULT_RESOLUTION = 'high' NOTIFICATION_ID = 'amcrest_notification' NOTIFICATION_TITLE = 'Amcrest Camera Setup' +RESOLUTION_LIST = { + 'high': 0, + 'low': 1, +} + PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_HOST): cv.string, vol.Required(CONF_USERNAME): cv.string, vol.Required(CONF_PASSWORD): cv.string, + vol.Optional(CONF_RESOLUTION, default=DEFAULT_RESOLUTION): + vol.All(vol.In(RESOLUTION_LIST)), vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port, }) @@ -64,13 +74,14 @@ class AmcrestCam(Camera): def __init__(self, device_info, data): """Initialize an Amcrest camera.""" super(AmcrestCam, self).__init__() - self._name = device_info.get(CONF_NAME) self._data = data + self._name = device_info.get(CONF_NAME) + self._resolution = RESOLUTION_LIST[device_info.get(CONF_RESOLUTION)] def camera_image(self): """Return a still image reponse from the camera.""" # Send the request to snap a picture and return raw jpg data - response = self._data.camera.snapshot() + response = self._data.camera.snapshot(channel=self._resolution) return response.data @property