Add support for sensor classes
This commit is contained in:
parent
37b6aa593e
commit
ee36c36783
1 changed files with 20 additions and 6 deletions
|
@ -9,7 +9,8 @@ from datetime import timedelta
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import BinarySensorDevice
|
from homeassistant.components.binary_sensor import (BinarySensorDevice,
|
||||||
|
SENSOR_CLASSES)
|
||||||
from homeassistant.util import Throttle
|
from homeassistant.util import Throttle
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -26,6 +27,11 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
resource = config.get(CONF_RESOURCE)
|
resource = config.get(CONF_RESOURCE)
|
||||||
pin = config.get(CONF_PIN)
|
pin = config.get(CONF_PIN)
|
||||||
|
|
||||||
|
sensor_class = config.get('sensor_class')
|
||||||
|
if sensor_class not in SENSOR_CLASSES:
|
||||||
|
_LOGGER.warning('Unknown sensor class: %s', sensor_class)
|
||||||
|
sensor_class = None
|
||||||
|
|
||||||
if None in (resource, pin):
|
if None in (resource, pin):
|
||||||
_LOGGER.error('Not all required config keys present: %s',
|
_LOGGER.error('Not all required config keys present: %s',
|
||||||
', '.join((CONF_RESOURCE, CONF_PIN)))
|
', '.join((CONF_RESOURCE, CONF_PIN)))
|
||||||
|
@ -45,21 +51,24 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
|
||||||
arest = ArestData(resource, pin)
|
arest = ArestData(resource, pin)
|
||||||
|
|
||||||
add_devices([ArestBinarySensor(arest,
|
add_devices([ArestBinarySensor(
|
||||||
resource,
|
arest,
|
||||||
config.get('name', response['name']),
|
resource,
|
||||||
pin)])
|
config.get('name', response['name']),
|
||||||
|
sensor_class,
|
||||||
|
pin)])
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-many-instance-attributes, too-many-arguments
|
# pylint: disable=too-many-instance-attributes, too-many-arguments
|
||||||
class ArestBinarySensor(BinarySensorDevice):
|
class ArestBinarySensor(BinarySensorDevice):
|
||||||
"""Implement an aREST binary sensor for a pin."""
|
"""Implement an aREST binary sensor for a pin."""
|
||||||
|
|
||||||
def __init__(self, arest, resource, name, pin):
|
def __init__(self, arest, resource, name, sensor_class, pin):
|
||||||
"""Initialize the aREST device."""
|
"""Initialize the aREST device."""
|
||||||
self.arest = arest
|
self.arest = arest
|
||||||
self._resource = resource
|
self._resource = resource
|
||||||
self._name = name
|
self._name = name
|
||||||
|
self._sensor_class = sensor_class
|
||||||
self._pin = pin
|
self._pin = pin
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
|
@ -79,6 +88,11 @@ class ArestBinarySensor(BinarySensorDevice):
|
||||||
"""Return true if the binary sensor is on."""
|
"""Return true if the binary sensor is on."""
|
||||||
return bool(self.arest.data.get('state'))
|
return bool(self.arest.data.get('state'))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def sensor_class(self):
|
||||||
|
"""Return the class of this sensor."""
|
||||||
|
return self._sensor_class
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Get the latest data from aREST API."""
|
"""Get the latest data from aREST API."""
|
||||||
self.arest.update()
|
self.arest.update()
|
||||||
|
|
Loading…
Add table
Reference in a new issue