Merge pull request #598 from SEJeff/update-foscam-snapshot

Make a single request to get the foscam camera image
This commit is contained in:
Paulus Schoutsen 2015-11-08 19:57:21 -08:00
commit ffce252a12

View File

@ -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__)
@ -40,7 +39,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 +49,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