2019-02-14 04:35:12 +00:00
|
|
|
"""Support for Lupusec Security System binary sensors."""
|
2022-01-03 10:32:26 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2018-11-07 11:51:12 +00:00
|
|
|
from datetime import timedelta
|
2024-01-25 17:52:30 +00:00
|
|
|
import logging
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2019-10-21 08:07:09 +00:00
|
|
|
import lupupy.constants as CONST
|
|
|
|
|
2024-01-25 17:52:30 +00:00
|
|
|
from homeassistant.components.binary_sensor import (
|
|
|
|
BinarySensorDeviceClass,
|
|
|
|
BinarySensorEntity,
|
|
|
|
)
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2022-01-03 10:32:26 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2018-11-07 11:51:12 +00:00
|
|
|
|
2024-01-28 15:06:57 +00:00
|
|
|
from . import DOMAIN
|
|
|
|
from .entity import LupusecBaseSensor
|
2018-11-07 11:51:12 +00:00
|
|
|
|
|
|
|
SCAN_INTERVAL = timedelta(seconds=2)
|
|
|
|
|
2024-01-25 17:52:30 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
2018-11-07 11:51:12 +00:00
|
|
|
|
2024-01-25 17:52:30 +00:00
|
|
|
|
|
|
|
async def async_setup_entry(
|
2022-01-03 10:32:26 +00:00
|
|
|
hass: HomeAssistant,
|
2024-01-25 17:52:30 +00:00
|
|
|
config_entry: ConfigEntry,
|
|
|
|
async_add_devices: AddEntitiesCallback,
|
2022-01-03 10:32:26 +00:00
|
|
|
) -> None:
|
2024-01-25 17:52:30 +00:00
|
|
|
"""Set up a binary sensors for a Lupusec device."""
|
2018-11-07 11:51:12 +00:00
|
|
|
|
2024-01-25 17:52:30 +00:00
|
|
|
data = hass.data[DOMAIN][config_entry.entry_id]
|
2018-11-07 11:51:12 +00:00
|
|
|
|
2023-11-15 12:39:34 +00:00
|
|
|
device_types = CONST.TYPE_OPENING + CONST.TYPE_SENSOR
|
2018-11-07 11:51:12 +00:00
|
|
|
|
2024-01-25 17:52:30 +00:00
|
|
|
sensors = []
|
2018-11-07 11:51:12 +00:00
|
|
|
for device in data.lupusec.get_devices(generic_type=device_types):
|
2024-01-28 15:06:57 +00:00
|
|
|
sensors.append(LupusecBinarySensor(data, device, config_entry.entry_id))
|
2018-11-07 11:51:12 +00:00
|
|
|
|
2024-01-25 17:52:30 +00:00
|
|
|
async_add_devices(sensors)
|
2018-11-07 11:51:12 +00:00
|
|
|
|
|
|
|
|
2024-01-28 15:06:57 +00:00
|
|
|
class LupusecBinarySensor(LupusecBaseSensor, BinarySensorEntity):
|
2018-11-07 11:51:12 +00:00
|
|
|
"""A binary sensor implementation for Lupusec device."""
|
|
|
|
|
2024-01-28 15:06:57 +00:00
|
|
|
_attr_name = None
|
|
|
|
|
2018-11-07 11:51:12 +00:00
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return True if the binary sensor is on."""
|
|
|
|
return self._device.is_on
|
|
|
|
|
|
|
|
@property
|
|
|
|
def device_class(self):
|
|
|
|
"""Return the class of the binary sensor."""
|
2024-01-25 17:52:30 +00:00
|
|
|
if self._device.generic_type not in (
|
|
|
|
item.value for item in BinarySensorDeviceClass
|
|
|
|
):
|
2018-11-07 11:51:12 +00:00
|
|
|
return None
|
|
|
|
return self._device.generic_type
|