2019-02-13 21:21:14 +01:00
|
|
|
"""Support for Abode Security System binary sensors."""
|
2022-01-10 09:54:09 -05:00
|
|
|
from typing import cast
|
|
|
|
|
|
|
|
from abodepy.devices.binary_sensor import AbodeBinarySensor as ABBinarySensor
|
2019-10-12 22:02:12 +02:00
|
|
|
import abodepy.helpers.constants as CONST
|
|
|
|
|
2020-03-16 07:03:42 -07:00
|
|
|
from homeassistant.components.binary_sensor import (
|
2021-12-08 19:58:01 +01:00
|
|
|
BinarySensorDeviceClass,
|
2020-04-23 21:57:07 +02:00
|
|
|
BinarySensorEntity,
|
2020-03-16 07:03:42 -07:00
|
|
|
)
|
2021-12-24 14:06:14 +01:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2017-08-29 08:34:19 -07:00
|
|
|
|
2022-01-10 09:54:09 -05:00
|
|
|
from . import AbodeDevice, AbodeSystem
|
2020-02-23 22:38:05 +01:00
|
|
|
from .const import DOMAIN
|
2019-03-20 22:56:46 -07:00
|
|
|
|
2017-08-20 10:55:48 -04:00
|
|
|
|
2021-12-24 14:06:14 +01:00
|
|
|
async def async_setup_entry(
|
2022-01-10 09:54:09 -05:00
|
|
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
2021-12-24 14:06:14 +01:00
|
|
|
) -> None:
|
2019-11-08 22:35:45 -08:00
|
|
|
"""Set up Abode binary sensor devices."""
|
2022-01-10 09:54:09 -05:00
|
|
|
data: AbodeSystem = hass.data[DOMAIN]
|
2017-08-20 10:55:48 -04:00
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
device_types = [
|
|
|
|
CONST.TYPE_CONNECTIVITY,
|
|
|
|
CONST.TYPE_MOISTURE,
|
|
|
|
CONST.TYPE_MOTION,
|
|
|
|
CONST.TYPE_OCCUPANCY,
|
|
|
|
CONST.TYPE_OPENING,
|
|
|
|
]
|
2017-08-20 10:55:48 -04:00
|
|
|
|
2022-08-10 18:09:05 -04:00
|
|
|
async_add_entities(
|
|
|
|
AbodeBinarySensor(data, device)
|
|
|
|
for device in data.abode.get_devices(generic_type=device_types)
|
|
|
|
)
|
2017-08-20 10:55:48 -04:00
|
|
|
|
|
|
|
|
2020-04-23 21:57:07 +02:00
|
|
|
class AbodeBinarySensor(AbodeDevice, BinarySensorEntity):
|
2017-08-29 08:34:19 -07:00
|
|
|
"""A binary sensor implementation for Abode device."""
|
|
|
|
|
2022-01-10 09:54:09 -05:00
|
|
|
_device: ABBinarySensor
|
|
|
|
|
2017-08-20 10:55:48 -04:00
|
|
|
@property
|
2022-01-10 09:54:09 -05:00
|
|
|
def is_on(self) -> bool:
|
2017-08-20 10:55:48 -04:00
|
|
|
"""Return True if the binary sensor is on."""
|
2022-01-10 09:54:09 -05:00
|
|
|
return cast(bool, self._device.is_on)
|
2017-08-20 10:55:48 -04:00
|
|
|
|
|
|
|
@property
|
2022-01-10 09:54:09 -05:00
|
|
|
def device_class(self) -> str:
|
2017-08-20 10:55:48 -04:00
|
|
|
"""Return the class of the binary sensor."""
|
2020-03-16 07:03:42 -07:00
|
|
|
if self._device.get_value("is_window") == "1":
|
2021-12-08 19:58:01 +01:00
|
|
|
return BinarySensorDeviceClass.WINDOW
|
2022-01-10 09:54:09 -05:00
|
|
|
return cast(str, self._device.generic_type)
|