diff --git a/homeassistant/components/android_ip_webcam.py b/homeassistant/components/android_ip_webcam.py index b51045be3d9..3b6de5c4892 100644 --- a/homeassistant/components/android_ip_webcam.py +++ b/homeassistant/components/android_ip_webcam.py @@ -23,7 +23,7 @@ from homeassistant.helpers.event import async_track_point_in_utc_time from homeassistant.util.dt import utcnow DOMAIN = 'android_ip_webcam' -REQUIREMENTS = ["pydroid-ipcam==0.1"] +REQUIREMENTS = ["pydroid-ipcam==0.2"] SCAN_INTERVAL = timedelta(seconds=10) @@ -161,7 +161,7 @@ def async_setup(hass, config): username = cam_config.get(CONF_USERNAME) password = cam_config.get(CONF_PASSWORD) name = cam_config[CONF_NAME] - interval = cam_config[SCAN_INTERVAL] + interval = cam_config[CONF_SCAN_INTERVAL] cam = PyDroidIPCam( hass.loop, websession, host, cam_config[CONF_PORT], @@ -176,12 +176,13 @@ def async_setup(hass, config): async_dispatcher_send(hass, SIGNAL_UPDATE_DATA, host) async_track_point_in_utc_time( - hass, utcnow() + interval, async_update_data) + hass, async_update_data, utcnow() + interval) yield from async_update_data(None) webcams[host] = cam mjpeg_camera = { + 'platform': 'mjpeg', 'mjpeg_url': cam.mjpeg_url, 'still_image_url': cam.image_url, CONF_NAME: name, @@ -246,7 +247,7 @@ class AndroidIPCamEntity(Entity): @property def should_poll(self): - """Is update over central callback.""" + """Return True if entity has to be polled for state.""" return False @property diff --git a/homeassistant/components/binary_sensor/android_ip_webcam.py b/homeassistant/components/binary_sensor/android_ip_webcam.py index ff193316439..8c0699040ed 100644 --- a/homeassistant/components/binary_sensor/android_ip_webcam.py +++ b/homeassistant/components/binary_sensor/android_ip_webcam.py @@ -6,6 +6,7 @@ https://home-assistant.io/components/binary_sensor.android_ip_webcam/ """ import asyncio +from homeassistant.const import STATE_UNKNOWN from homeassistant.components.binary_sensor import BinarySensorDevice from homeassistant.components.android_ip_webcam import ( KEY_MAP, DATA_IP_WEBCAM, AndroidIPCamEntity, CONF_HOST, CONF_NAME) @@ -54,6 +55,11 @@ class IPWebcamBinarySensor(AndroidIPCamEntity, BinarySensorDevice): def async_update(self): """Retrieve latest state.""" if self._ipcam.status_data is None: + self._state = STATE_UNKNOWN + return + + if self._sensor not in self._ipcam.enabled_sensors: + self._state = STATE_UNKNOWN return container = self._ipcam.sensor_data.get(self._sensor) @@ -61,6 +67,6 @@ class IPWebcamBinarySensor(AndroidIPCamEntity, BinarySensorDevice): self._state = data_point[0][-1][0] == 1.0 @property - def sensor_class(self): + def device_class(self): """Return the class of this device, from component DEVICE_CLASSES.""" return 'motion' diff --git a/homeassistant/components/camera/mjpeg.py b/homeassistant/components/camera/mjpeg.py index fa46ea55e2c..532b91e7442 100644 --- a/homeassistant/components/camera/mjpeg.py +++ b/homeassistant/components/camera/mjpeg.py @@ -45,6 +45,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ # pylint: disable=unused-argument def async_setup_platform(hass, config, async_add_devices, discovery_info=None): """Setup a MJPEG IP Camera.""" + if discovery_info: + config = PLATFORM_SCHEMA(discovery_info) async_add_devices([MjpegCamera(hass, config)]) diff --git a/homeassistant/components/sensor/android_ip_webcam.py b/homeassistant/components/sensor/android_ip_webcam.py index f0151758b48..14a77da632e 100644 --- a/homeassistant/components/sensor/android_ip_webcam.py +++ b/homeassistant/components/sensor/android_ip_webcam.py @@ -6,6 +6,7 @@ https://home-assistant.io/components/sensor.android_ip_webcam/ """ import asyncio +from homeassistant.const import STATE_UNKNOWN from homeassistant.components.android_ip_webcam import ( KEY_MAP, ICON_MAP, DATA_IP_WEBCAM, AndroidIPCamEntity, CONF_HOST, CONF_NAME, CONF_SENSORS) @@ -64,6 +65,11 @@ class IPWebcamSensor(AndroidIPCamEntity): def async_update(self): """Retrieve latest state.""" if self._ipcam.status_data is None or self._ipcam.sensor_data is None: + self._state = STATE_UNKNOWN + return + + if self._sensor not in self._ipcam.enabled_sensors: + self._state = STATE_UNKNOWN return if self._sensor in ('audio_connections', 'video_connections'): diff --git a/homeassistant/components/switch/android_ip_webcam.py b/homeassistant/components/switch/android_ip_webcam.py index 04d11be93fa..6362e0c5261 100644 --- a/homeassistant/components/switch/android_ip_webcam.py +++ b/homeassistant/components/switch/android_ip_webcam.py @@ -6,6 +6,7 @@ https://home-assistant.io/components/switch.android_ip_webcam/ """ import asyncio +from homeassistant.const import STATE_UNKNOWN from homeassistant.components.switch import SwitchDevice from homeassistant.components.android_ip_webcam import ( KEY_MAP, ICON_MAP, DATA_IP_WEBCAM, AndroidIPCamEntity, CONF_HOST, @@ -42,7 +43,7 @@ class IPWebcamSettingsSwitch(AndroidIPCamEntity, SwitchDevice): self._setting = setting self._mapped_name = KEY_MAP.get(self._setting, self._setting) - self._name = '{} {}'.format(self._device.name, self._mapped_name) + self._name = '{} {}'.format(name, self._mapped_name) self._state = False @property @@ -55,6 +56,8 @@ class IPWebcamSettingsSwitch(AndroidIPCamEntity, SwitchDevice): """Get the updated status of the switch.""" if self._ipcam.status_data is not None: self._state = self._ipcam.current_settings.get(self._setting) + else: + self._state = STATE_UNKNOWN @property def is_on(self): diff --git a/requirements_all.txt b/requirements_all.txt index 886fb65e936..cba53d3a13d 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.1 +pydroid-ipcam==0.2 # homeassistant.components.sensor.ebox pyebox==0.1.0