2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Abode Security System binary sensors."""
|
2019-10-12 20:02:12 +00:00
|
|
|
import abodepy.helpers.constants as CONST
|
|
|
|
|
2020-03-16 14:03:42 +00:00
|
|
|
from homeassistant.components.binary_sensor import (
|
|
|
|
DEVICE_CLASS_WINDOW,
|
2020-04-23 19:57:07 +00:00
|
|
|
BinarySensorEntity,
|
2020-03-16 14:03:42 +00:00
|
|
|
)
|
2017-08-29 15:34:19 +00:00
|
|
|
|
2020-03-04 22:54:28 +00:00
|
|
|
from . import AbodeDevice
|
2020-02-23 21:38:05 +00:00
|
|
|
from .const import DOMAIN
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2017-08-20 14:55:48 +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 binary sensor devices."""
|
2019-10-13 18:01:04 +00:00
|
|
|
data = hass.data[DOMAIN]
|
2017-08-20 14:55:48 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
device_types = [
|
|
|
|
CONST.TYPE_CONNECTIVITY,
|
|
|
|
CONST.TYPE_MOISTURE,
|
|
|
|
CONST.TYPE_MOTION,
|
|
|
|
CONST.TYPE_OCCUPANCY,
|
|
|
|
CONST.TYPE_OPENING,
|
|
|
|
]
|
2017-08-20 14:55:48 +00:00
|
|
|
|
2019-11-09 06:35:45 +00:00
|
|
|
entities = []
|
2017-08-20 14:55:48 +00:00
|
|
|
|
2019-10-13 18:01:04 +00:00
|
|
|
for device in data.abode.get_devices(generic_type=device_types):
|
2019-11-09 06:35:45 +00:00
|
|
|
entities.append(AbodeBinarySensor(data, device))
|
2017-08-20 14:55:48 +00:00
|
|
|
|
2019-11-09 06:35:45 +00:00
|
|
|
async_add_entities(entities)
|
2017-08-20 14:55:48 +00:00
|
|
|
|
|
|
|
|
2020-04-23 19:57:07 +00:00
|
|
|
class AbodeBinarySensor(AbodeDevice, BinarySensorEntity):
|
2017-08-29 15:34:19 +00:00
|
|
|
"""A binary sensor implementation for Abode device."""
|
|
|
|
|
2017-08-20 14:55:48 +00:00
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return True if the binary sensor is on."""
|
2017-08-29 15:34:19 +00:00
|
|
|
return self._device.is_on
|
2017-08-20 14:55:48 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def device_class(self):
|
|
|
|
"""Return the class of the binary sensor."""
|
2020-03-16 14:03:42 +00:00
|
|
|
if self._device.get_value("is_window") == "1":
|
|
|
|
return DEVICE_CLASS_WINDOW
|
2017-09-18 15:39:41 +00:00
|
|
|
return self._device.generic_type
|