From 44da43065ff109292e767c4c77a0234155114e85 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Fri, 10 Mar 2017 23:10:35 +0100 Subject: [PATCH] Android webcam better error handling / pump library 0.4 (#6518) --- homeassistant/components/android_ip_webcam.py | 31 ++++++++++--------- .../components/sensor/android_ip_webcam.py | 2 ++ .../components/switch/android_ip_webcam.py | 12 +++---- requirements_all.txt | 2 +- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/homeassistant/components/android_ip_webcam.py b/homeassistant/components/android_ip_webcam.py index 43a04190466..e6810a67029 100644 --- a/homeassistant/components/android_ip_webcam.py +++ b/homeassistant/components/android_ip_webcam.py @@ -27,7 +27,7 @@ from homeassistant.components.camera.mjpeg import ( CONF_MJPEG_URL, CONF_STILL_IMAGE_URL) DOMAIN = 'android_ip_webcam' -REQUIREMENTS = ["pydroid-ipcam==0.3"] +REQUIREMENTS = ["pydroid-ipcam==0.4"] _LOGGER = logging.getLogger(__name__) SCAN_INTERVAL = timedelta(seconds=10) @@ -199,7 +199,7 @@ def async_setup(hass, config): if cam_config[CONF_AUTO_DISCOVERY]: if not cam.available: _LOGGER.error( - "Android webcam %s not found for discovery!", host) + "Android webcam %s not found for discovery!", cam.base_url) return sensors = [sensor for sensor in cam.enabled_sensors @@ -207,6 +207,7 @@ def async_setup(hass, config): switches = [setting for setting in cam.enabled_settings if setting in SWITCHES] motion = True if 'motion_active' in cam.enabled_sensors else False + sensors.extend(['audio_connections', 'video_connections']) # load platforms webcams[host] = cam @@ -226,19 +227,21 @@ def async_setup(hass, config): hass.async_add_job(discovery.async_load_platform( hass, 'camera', 'mjpeg', mjpeg_camera, config)) - hass.async_add_job(discovery.async_load_platform( - hass, 'sensor', DOMAIN, { - CONF_NAME: name, - CONF_HOST: host, - CONF_SENSORS: sensors, - }, config)) + if sensors: + hass.async_add_job(discovery.async_load_platform( + hass, 'sensor', DOMAIN, { + CONF_NAME: name, + CONF_HOST: host, + CONF_SENSORS: sensors, + }, config)) - hass.async_add_job(discovery.async_load_platform( - hass, 'switch', DOMAIN, { - CONF_NAME: name, - CONF_HOST: host, - CONF_SWITCHES: switches, - }, config)) + if switches: + hass.async_add_job(discovery.async_load_platform( + hass, 'switch', DOMAIN, { + CONF_NAME: name, + CONF_HOST: host, + CONF_SWITCHES: switches, + }, config)) if motion: hass.async_add_job(discovery.async_load_platform( diff --git a/homeassistant/components/sensor/android_ip_webcam.py b/homeassistant/components/sensor/android_ip_webcam.py index 5b7099d1c96..687649e226a 100644 --- a/homeassistant/components/sensor/android_ip_webcam.py +++ b/homeassistant/components/sensor/android_ip_webcam.py @@ -64,6 +64,8 @@ class IPWebcamSensor(AndroidIPCamEntity): def async_update(self): """Retrieve latest state.""" if self._sensor in ('audio_connections', 'video_connections'): + if not self._ipcam.status_data: + return self._state = self._ipcam.status_data.get(self._sensor) self._unit = 'Connections' else: diff --git a/homeassistant/components/switch/android_ip_webcam.py b/homeassistant/components/switch/android_ip_webcam.py index 6e3b9ed77f1..8c8f04b6161 100644 --- a/homeassistant/components/switch/android_ip_webcam.py +++ b/homeassistant/components/switch/android_ip_webcam.py @@ -63,11 +63,11 @@ class IPWebcamSettingsSwitch(AndroidIPCamEntity, SwitchDevice): @asyncio.coroutine def async_turn_on(self, **kwargs): """Turn device on.""" - if self._setting is 'torch': + if self._setting == 'torch': yield from self._ipcam.torch(activate=True) - elif self._setting is 'focus': + elif self._setting == 'focus': yield from self._ipcam.focus(activate=True) - elif self._setting is 'video_recording': + elif self._setting == 'video_recording': yield from self._ipcam.record(record=True) else: yield from self._ipcam.change_setting(self._setting, True) @@ -77,11 +77,11 @@ class IPWebcamSettingsSwitch(AndroidIPCamEntity, SwitchDevice): @asyncio.coroutine def async_turn_off(self, **kwargs): """Turn device off.""" - if self._setting is 'torch': + if self._setting == 'torch': yield from self._ipcam.torch(activate=False) - elif self._setting is 'focus': + elif self._setting == 'focus': yield from self._ipcam.focus(activate=False) - elif self._setting is 'video_recording': + elif self._setting == 'video_recording': yield from self._ipcam.record(record=False) else: yield from self._ipcam.change_setting(self._setting, False) diff --git a/requirements_all.txt b/requirements_all.txt index 5991de37372..5a4f4b6080b 100755 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -482,7 +482,7 @@ pycmus==0.1.0 pydispatcher==2.0.5 # homeassistant.components.android_ip_webcam -pydroid-ipcam==0.3 +pydroid-ipcam==0.4 # homeassistant.components.sensor.ebox pyebox==0.1.0