From 137cadb59cd587ddc1fd62b1ac2398ef1db30c6b Mon Sep 17 00:00:00 2001 From: Jeff Schroeder Date: Tue, 3 Nov 2015 22:02:28 -0600 Subject: [PATCH 1/2] Make a single request to get the foscam camera image This uses the `snapPicture2` command, which is documented in their cgi sdk to return raw jpeg data instead of html containing the image --- homeassistant/components/camera/foscam.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/camera/foscam.py b/homeassistant/components/camera/foscam.py index 24a42cbf883..c1b23cb9b37 100644 --- a/homeassistant/components/camera/foscam.py +++ b/homeassistant/components/camera/foscam.py @@ -40,7 +40,7 @@ class FoscamCamera(Camera): self._username = device_info.get('username') self._password = device_info.get('password') self._snap_picture_url = self._base_url \ - + 'cgi-bin/CGIProxy.fcgi?cmd=snapPicture&usr=' \ + + 'cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=' \ + self._username + '&pwd=' + self._password self._name = device_info.get('name', 'Foscam Camera') @@ -50,17 +50,9 @@ class FoscamCamera(Camera): def camera_image(self): """ Return a still image reponse from the camera. """ - # send the request to snap a picture + # Send the request to snap a picture and return raw jpg data response = requests.get(self._snap_picture_url) - # parse the response to find the image file name - - pattern = re.compile('src="[.][.]/(.*[.]jpg)"') - filename = pattern.search(response.content.decode("utf-8")).group(1) - - # send request for the image - response = requests.get(self._base_url + filename) - return response.content @property From 0f292e8fa688cde190689aeb46fcd830b8e56549 Mon Sep 17 00:00:00 2001 From: Jeff Schroeder Date: Sun, 8 Nov 2015 20:37:29 -0600 Subject: [PATCH 2/2] Remove unused import for re --- homeassistant/components/camera/foscam.py | 1 - 1 file changed, 1 deletion(-) diff --git a/homeassistant/components/camera/foscam.py b/homeassistant/components/camera/foscam.py index c1b23cb9b37..bbcb8eee634 100644 --- a/homeassistant/components/camera/foscam.py +++ b/homeassistant/components/camera/foscam.py @@ -11,7 +11,6 @@ from homeassistant.helpers import validate_config from homeassistant.components.camera import DOMAIN from homeassistant.components.camera import Camera import requests -import re _LOGGER = logging.getLogger(__name__)