Skip to content

Commit

Permalink
Foscam Camera: Adding exception handling when fetching the camera ima…
Browse files Browse the repository at this point in the history
…ge to avoid python exception errors when host is not reachable or rather any url error to camera (#6964)

* Adding exception handling when fetching the camera image to avoid python errors when host is not reachable or any url errors to camera

* Added exception as ConnectionError instead of plain except

* Added exception as ConnectionError instead of plain except. Removed the unused error handle
  • Loading branch information
viswa-swami authored and balloob committed Apr 7, 2017
1 parent f96e06a commit 9254e7e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions homeassistant/components/camera/foscam.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,13 @@ def __init__(self, device_info):
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 = requests.get(self._snap_picture_url, timeout=10)

return response.content
# Handle exception if host is not reachable or url failed
try:
response = requests.get(self._snap_picture_url, timeout=10)
except requests.exceptions.ConnectionError:
return None
else:
return response.content

@property
def name(self):
Expand Down

0 comments on commit 9254e7e

Please sign in to comment.