2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Abode Security System sensors."""
|
2019-10-12 20:02:12 +00:00
|
|
|
import abodepy.helpers.constants as CONST
|
|
|
|
|
2018-05-05 13:37:40 +00:00
|
|
|
from homeassistant.const import (
|
2019-07-31 19:25:30 +00:00
|
|
|
DEVICE_CLASS_HUMIDITY,
|
|
|
|
DEVICE_CLASS_ILLUMINANCE,
|
|
|
|
DEVICE_CLASS_TEMPERATURE,
|
|
|
|
)
|
2017-10-07 08:25:53 +00:00
|
|
|
|
2019-10-13 18:01:04 +00:00
|
|
|
from . import AbodeDevice
|
|
|
|
from .const import DOMAIN
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2017-10-07 08:25:53 +00:00
|
|
|
# Sensor types: Name, icon
|
|
|
|
SENSOR_TYPES = {
|
2019-11-04 20:49:11 +00:00
|
|
|
CONST.TEMP_STATUS_KEY: ["Temperature", DEVICE_CLASS_TEMPERATURE],
|
|
|
|
CONST.HUMI_STATUS_KEY: ["Humidity", DEVICE_CLASS_HUMIDITY],
|
|
|
|
CONST.LUX_STATUS_KEY: ["Lux", DEVICE_CLASS_ILLUMINANCE],
|
2017-10-07 08:25:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-10-13 18:01:04 +00:00
|
|
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
2019-11-09 06:35:45 +00:00
|
|
|
"""Set up Abode sensor devices."""
|
2019-10-13 18:01:04 +00:00
|
|
|
data = hass.data[DOMAIN]
|
2019-11-09 06:35:45 +00:00
|
|
|
|
2019-11-04 20:49:11 +00:00
|
|
|
entities = []
|
2017-10-07 08:25:53 +00:00
|
|
|
|
|
|
|
for device in data.abode.get_devices(generic_type=CONST.TYPE_SENSOR):
|
|
|
|
for sensor_type in SENSOR_TYPES:
|
2019-11-04 20:49:11 +00:00
|
|
|
if sensor_type not in device.get_value(CONST.STATUSES_KEY):
|
|
|
|
continue
|
|
|
|
entities.append(AbodeSensor(data, device, sensor_type))
|
2017-10-07 08:25:53 +00:00
|
|
|
|
2019-11-04 20:49:11 +00:00
|
|
|
async_add_entities(entities)
|
2017-10-07 08:25:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
class AbodeSensor(AbodeDevice):
|
|
|
|
"""A sensor implementation for Abode devices."""
|
|
|
|
|
|
|
|
def __init__(self, data, device, sensor_type):
|
|
|
|
"""Initialize a sensor for an Abode device."""
|
|
|
|
super().__init__(data, device)
|
|
|
|
self._sensor_type = sensor_type
|
2020-02-23 21:38:05 +00:00
|
|
|
self._name = f"{self._device.name} {SENSOR_TYPES[self._sensor_type][0]}"
|
2018-05-05 13:37:40 +00:00
|
|
|
self._device_class = SENSOR_TYPES[self._sensor_type][1]
|
2017-10-07 08:25:53 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Return the name of the sensor."""
|
|
|
|
return self._name
|
|
|
|
|
2018-05-05 13:37:40 +00:00
|
|
|
@property
|
|
|
|
def device_class(self):
|
|
|
|
"""Return the device class."""
|
|
|
|
return self._device_class
|
|
|
|
|
2019-11-04 20:49:11 +00:00
|
|
|
@property
|
|
|
|
def unique_id(self):
|
|
|
|
"""Return a unique ID to use for this device."""
|
|
|
|
return f"{self._device.device_uuid}-{self._sensor_type}"
|
|
|
|
|
2017-10-07 08:25:53 +00:00
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
"""Return the state of the sensor."""
|
2019-11-23 11:29:54 +00:00
|
|
|
if self._sensor_type == CONST.TEMP_STATUS_KEY:
|
2017-10-07 08:25:53 +00:00
|
|
|
return self._device.temp
|
2019-11-23 11:29:54 +00:00
|
|
|
if self._sensor_type == CONST.HUMI_STATUS_KEY:
|
2017-10-07 08:25:53 +00:00
|
|
|
return self._device.humidity
|
2019-11-23 11:29:54 +00:00
|
|
|
if self._sensor_type == CONST.LUX_STATUS_KEY:
|
2017-10-07 08:25:53 +00:00
|
|
|
return self._device.lux
|
|
|
|
|
|
|
|
@property
|
|
|
|
def unit_of_measurement(self):
|
|
|
|
"""Return the units of measurement."""
|
2019-11-23 11:29:54 +00:00
|
|
|
if self._sensor_type == CONST.TEMP_STATUS_KEY:
|
2017-10-07 08:25:53 +00:00
|
|
|
return self._device.temp_unit
|
2019-11-23 11:29:54 +00:00
|
|
|
if self._sensor_type == CONST.HUMI_STATUS_KEY:
|
2017-10-07 08:25:53 +00:00
|
|
|
return self._device.humidity_unit
|
2019-11-23 11:29:54 +00:00
|
|
|
if self._sensor_type == CONST.LUX_STATUS_KEY:
|
2017-10-07 08:25:53 +00:00
|
|
|
return self._device.lux_unit
|