Android webcam better error handling / pump library 0.4 (#6518)

This commit is contained in:
Pascal Vizeli 2017-03-10 23:10:35 +01:00 committed by GitHub
parent ffb1613d55
commit 44da43065f
4 changed files with 26 additions and 21 deletions

View File

@ -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,6 +227,7 @@ def async_setup(hass, config):
hass.async_add_job(discovery.async_load_platform(
hass, 'camera', 'mjpeg', mjpeg_camera, config))
if sensors:
hass.async_add_job(discovery.async_load_platform(
hass, 'sensor', DOMAIN, {
CONF_NAME: name,
@ -233,6 +235,7 @@ def async_setup(hass, config):
CONF_SENSORS: sensors,
}, config))
if switches:
hass.async_add_job(discovery.async_load_platform(
hass, 'switch', DOMAIN, {
CONF_NAME: name,

View File

@ -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:

View File

@ -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)

View File

@ -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