Files
homeassistant-core/homeassistant/components/abode/binary_sensor.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

67 lines
1.8 KiB
Python
Raw Normal View History

"""Support for Abode Security System binary sensors."""
from __future__ import annotations
2022-01-10 09:54:09 -05:00
from typing import cast
2024-03-12 18:38:57 +01:00
from jaraco.abode.devices.sensor import BinarySensor
from jaraco.abode.helpers.constants import (
TYPE_CONNECTIVITY,
TYPE_MOISTURE,
TYPE_MOTION,
TYPE_OCCUPANCY,
TYPE_OPENING,
)
2019-10-12 22:02:12 +02:00
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
from homeassistant.util.enum import try_parse_enum
from . import AbodeSystem
from .const import DOMAIN
from .entity import AbodeDevice
async def async_setup_entry(
2022-01-10 09:54:09 -05:00
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
"""Set up Abode binary sensor devices."""
2022-01-10 09:54:09 -05:00
data: AbodeSystem = hass.data[DOMAIN]
device_types = [
2024-03-12 18:38:57 +01:00
TYPE_CONNECTIVITY,
TYPE_MOISTURE,
TYPE_MOTION,
TYPE_OCCUPANCY,
TYPE_OPENING,
]
async_add_entities(
AbodeBinarySensor(data, device)
for device in data.abode.get_devices(generic_type=device_types)
)
class AbodeBinarySensor(AbodeDevice, BinarySensorEntity):
"""A binary sensor implementation for Abode device."""
_attr_name = None
2024-03-12 18:38:57 +01:00
_device: BinarySensor
2022-01-10 09:54:09 -05:00
@property
2022-01-10 09:54:09 -05:00
def is_on(self) -> bool:
"""Return True if the binary sensor is on."""
2022-01-10 09:54:09 -05:00
return cast(bool, self._device.is_on)
@property
def device_class(self) -> BinarySensorDeviceClass | None:
"""Return the class of the binary sensor."""
if self._device.get_value("is_window") == "1":
return BinarySensorDeviceClass.WINDOW
return try_parse_enum(BinarySensorDeviceClass, self._device.generic_type)