Fix some things

pull/6488/head
Pascal Vizeli 2017-03-09 01:00:57 +01:00
parent b1736994b7
commit 185ccc4fc4
6 changed files with 25 additions and 7 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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