From 137cadb59cd587ddc1fd62b1ac2398ef1db30c6b Mon Sep 17 00:00:00 2001 From: Jeff Schroeder Date: Tue, 3 Nov 2015 22:02:28 -0600 Subject: [PATCH] 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