core/homeassistant/components/abode/binary_sensor.py

57 lines
1.6 KiB
Python
Raw Normal View History

"""Support for Abode Security System binary sensors."""
2022-01-10 14:54:09 +00:00
from typing import cast
from abodepy.devices.binary_sensor import AbodeBinarySensor as ABBinarySensor
2019-10-12 20:02:12 +00:00
import abodepy.helpers.constants as CONST
from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
BinarySensorEntity,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
2022-01-10 14:54:09 +00:00
from . import AbodeDevice, AbodeSystem
from .const import DOMAIN
async def async_setup_entry(
2022-01-10 14:54:09 +00:00
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
"""Set up Abode binary sensor devices."""
2022-01-10 14:54:09 +00:00
data: AbodeSystem = hass.data[DOMAIN]
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,
]
entities = []
for device in data.abode.get_devices(generic_type=device_types):
entities.append(AbodeBinarySensor(data, device))
async_add_entities(entities)
class AbodeBinarySensor(AbodeDevice, BinarySensorEntity):
"""A binary sensor implementation for Abode device."""
2022-01-10 14:54:09 +00:00
_device: ABBinarySensor
@property
2022-01-10 14:54:09 +00:00
def is_on(self) -> bool:
"""Return True if the binary sensor is on."""
2022-01-10 14:54:09 +00:00
return cast(bool, self._device.is_on)
@property
2022-01-10 14:54:09 +00:00
def device_class(self) -> str:
"""Return the class of the binary sensor."""
if self._device.get_value("is_window") == "1":
return BinarySensorDeviceClass.WINDOW
2022-01-10 14:54:09 +00:00
return cast(str, self._device.generic_type)