hass-core/homeassistant/components/abode/sensor.py
shred86 1774a1427b Add abode config entries and device registry (#26699)
* Adds support for config entries and device registry

* Fixing string formatting for logger

* Add unit test for abode config flow

* Fix for lights, only allow one config, add ability to unload entry

* Fix for subscribing to hass_events on adding abode component

* Several fixes from code review

* Several fixes from second code review

* Several fixes from third code review

* Update documentation url to fix branch conflict

* Fixes config flow and removes unused constants

* Fix for switches, polling entry option, improved tests

* Update .coveragerc, disable pylint W0611, remove polling from UI

* Multiple fixes and edits to adhere to style guidelines

* Removed unique_id

* Minor correction for formatting error in rebase

* Resolves issue causing CI to fail

* Bump abodepy version

* Add remove device callback and minor clean up

* Fix incorrect method name

* Docstring edits

* Fix duplicate import issues from rebase

* Add logout_listener attribute to AbodeSystem

* Add additional test for complete coverage
2019-10-13 20:01:04 +02:00

83 lines
2.3 KiB
Python

"""Support for Abode Security System sensors."""
import logging
import abodepy.helpers.constants as CONST
from homeassistant.const import (
DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_ILLUMINANCE,
DEVICE_CLASS_TEMPERATURE,
)
from . import AbodeDevice
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
# Sensor types: Name, icon
SENSOR_TYPES = {
"temp": ["Temperature", DEVICE_CLASS_TEMPERATURE],
"humidity": ["Humidity", DEVICE_CLASS_HUMIDITY],
"lux": ["Lux", DEVICE_CLASS_ILLUMINANCE],
}
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Platform uses config entry setup."""
pass
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up a sensor for an Abode device."""
data = hass.data[DOMAIN]
devices = []
for device in data.abode.get_devices(generic_type=CONST.TYPE_SENSOR):
for sensor_type in SENSOR_TYPES:
devices.append(AbodeSensor(data, device, sensor_type))
async_add_entities(devices)
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
self._name = "{0} {1}".format(
self._device.name, SENSOR_TYPES[self._sensor_type][0]
)
self._device_class = SENSOR_TYPES[self._sensor_type][1]
@property
def name(self):
"""Return the name of the sensor."""
return self._name
@property
def device_class(self):
"""Return the device class."""
return self._device_class
@property
def state(self):
"""Return the state of the sensor."""
if self._sensor_type == "temp":
return self._device.temp
if self._sensor_type == "humidity":
return self._device.humidity
if self._sensor_type == "lux":
return self._device.lux
@property
def unit_of_measurement(self):
"""Return the units of measurement."""
if self._sensor_type == "temp":
return self._device.temp_unit
if self._sensor_type == "humidity":
return self._device.humidity_unit
if self._sensor_type == "lux":
return self._device.lux_unit