From 429e2cdde8fe7209e2fe54aef6b50b94ec66ef17 Mon Sep 17 00:00:00 2001 From: Chris Helming Date: Tue, 2 Apr 2019 12:59:38 -0400 Subject: [PATCH] Return 0 for failed Foscam streams (#22651) * Update Foscam to support stream source * Removing spaces and tabs * Changing to Python3-style string formatting * Adding '_media_port' to hopefully cover other models * changing logic for success and return none --- homeassistant/components/foscam/camera.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/foscam/camera.py b/homeassistant/components/foscam/camera.py index a11d2f48f62..b6f2162d57a 100644 --- a/homeassistant/components/foscam/camera.py +++ b/homeassistant/components/foscam/camera.py @@ -58,7 +58,10 @@ class FoscamCam(Camera): self._foscam_session = FoscamCamera( ip_address, port, self._username, self._password, verbose=False) - self._media_port = self._foscam_session.get_port_info()[1]['mediaPort'] + self._media_port = None + result, response = self._foscam_session.get_port_info() + if result == 0: + self._media_port = response['mediaPort'] def camera_image(self): """Return a still image response from the camera.""" @@ -73,16 +76,20 @@ class FoscamCam(Camera): @property def supported_features(self): """Return supported features.""" - return SUPPORT_STREAM + if self._media_port: + return SUPPORT_STREAM + return 0 @property def stream_source(self): """Return the stream source.""" - return 'rtsp://{}:{}@{}:{}/videoMain'.format( - self._username, - self._password, - self._foscam_session.host, - self._media_port) + if self._media_port: + return 'rtsp://{}:{}@{}:{}/videoMain'.format( + self._username, + self._password, + self._foscam_session.host, + self._media_port) + return None @property def motion_detection_enabled(self):