Add additional sensors for Arlo Baby camera (#15074)
* Add additional sensors for Arlo Baby camera * Fix linter errors * Fix linter error * Add tests for Arlo sensors * Fix linter errors * Bump pyarlo dependency to 0.1.9 * Remove unnecessary AttributeError except * Fix module reference error in py35 * Fix test * Address PR review concerns * Convert to standalone pytest methods * Fix linter errors * Fix linter errors * Fix linter errors * Fix test * Remove redundant check, fix async test * Fix linter error * Added check for total_cameras sensor, added additional attribute tests * Add missing docstring
This commit is contained in:
parent
f65c3940ae
commit
0f1bcfd63b
4 changed files with 294 additions and 9 deletions
|
@ -13,7 +13,10 @@ import homeassistant.helpers.config_validation as cv
|
|||
from homeassistant.components.arlo import (
|
||||
CONF_ATTRIBUTION, DEFAULT_BRAND, DATA_ARLO, SIGNAL_UPDATE_ARLO)
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import (ATTR_ATTRIBUTION, CONF_MONITORED_CONDITIONS)
|
||||
from homeassistant.const import (
|
||||
ATTR_ATTRIBUTION, CONF_MONITORED_CONDITIONS, TEMP_CELSIUS,
|
||||
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_HUMIDITY)
|
||||
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.icon import icon_for_battery_level
|
||||
|
@ -28,7 +31,10 @@ SENSOR_TYPES = {
|
|||
'total_cameras': ['Arlo Cameras', None, 'video'],
|
||||
'captured_today': ['Captured Today', None, 'file-video'],
|
||||
'battery_level': ['Battery Level', '%', 'battery-50'],
|
||||
'signal_strength': ['Signal Strength', None, 'signal']
|
||||
'signal_strength': ['Signal Strength', None, 'signal'],
|
||||
'temperature': ['Temperature', TEMP_CELSIUS, 'thermometer'],
|
||||
'humidity': ['Humidity', '%', 'water-percent'],
|
||||
'air_quality': ['Air Quality', 'ppm', 'biohazard']
|
||||
}
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
|
@ -41,7 +47,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
"""Set up an Arlo IP sensor."""
|
||||
arlo = hass.data.get(DATA_ARLO)
|
||||
if not arlo:
|
||||
return False
|
||||
return
|
||||
|
||||
sensors = []
|
||||
for sensor_type in config.get(CONF_MONITORED_CONDITIONS):
|
||||
|
@ -50,10 +56,24 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
SENSOR_TYPES[sensor_type][0], arlo, sensor_type))
|
||||
else:
|
||||
for camera in arlo.cameras:
|
||||
if sensor_type == 'temperature' or \
|
||||
sensor_type == 'humidity' or \
|
||||
sensor_type == 'air_quality':
|
||||
continue
|
||||
|
||||
name = '{0} {1}'.format(
|
||||
SENSOR_TYPES[sensor_type][0], camera.name)
|
||||
sensors.append(ArloSensor(name, camera, sensor_type))
|
||||
|
||||
for base_station in arlo.base_stations:
|
||||
if ((sensor_type == 'temperature' or
|
||||
sensor_type == 'humidity' or
|
||||
sensor_type == 'air_quality') and
|
||||
base_station.model_id == 'ABC1000'):
|
||||
name = '{0} {1}'.format(
|
||||
SENSOR_TYPES[sensor_type][0], base_station.name)
|
||||
sensors.append(ArloSensor(name, base_station, sensor_type))
|
||||
|
||||
add_devices(sensors, True)
|
||||
|
||||
|
||||
|
@ -62,6 +82,7 @@ class ArloSensor(Entity):
|
|||
|
||||
def __init__(self, name, device, sensor_type):
|
||||
"""Initialize an Arlo sensor."""
|
||||
_LOGGER.debug('ArloSensor created for %s', name)
|
||||
self._name = name
|
||||
self._data = device
|
||||
self._sensor_type = sensor_type
|
||||
|
@ -101,6 +122,15 @@ class ArloSensor(Entity):
|
|||
"""Return the units of measurement."""
|
||||
return SENSOR_TYPES.get(self._sensor_type)[1]
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Return the device class of the sensor."""
|
||||
if self._sensor_type == 'temperature':
|
||||
return DEVICE_CLASS_TEMPERATURE
|
||||
elif self._sensor_type == 'humidity':
|
||||
return DEVICE_CLASS_HUMIDITY
|
||||
return None
|
||||
|
||||
def update(self):
|
||||
"""Get the latest data and updates the state."""
|
||||
_LOGGER.debug("Updating Arlo sensor %s", self.name)
|
||||
|
@ -133,6 +163,24 @@ class ArloSensor(Entity):
|
|||
except TypeError:
|
||||
self._state = None
|
||||
|
||||
elif self._sensor_type == 'temperature':
|
||||
try:
|
||||
self._state = self._data.ambient_temperature
|
||||
except TypeError:
|
||||
self._state = None
|
||||
|
||||
elif self._sensor_type == 'humidity':
|
||||
try:
|
||||
self._state = self._data.ambient_humidity
|
||||
except TypeError:
|
||||
self._state = None
|
||||
|
||||
elif self._sensor_type == 'air_quality':
|
||||
try:
|
||||
self._state = self._data.ambient_air_quality
|
||||
except TypeError:
|
||||
self._state = None
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the device state attributes."""
|
||||
|
@ -141,10 +189,7 @@ class ArloSensor(Entity):
|
|||
attrs[ATTR_ATTRIBUTION] = CONF_ATTRIBUTION
|
||||
attrs['brand'] = DEFAULT_BRAND
|
||||
|
||||
if self._sensor_type == 'last_capture' or \
|
||||
self._sensor_type == 'captured_today' or \
|
||||
self._sensor_type == 'battery_level' or \
|
||||
self._sensor_type == 'signal_strength':
|
||||
if self._sensor_type != 'total_cameras':
|
||||
attrs['model'] = self._data.model_id
|
||||
|
||||
return attrs
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue