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
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2019-10-21 08:07:09 +00:00
|
|
|
import lupupy.constants as CONST
|
|
|
|
|
2020-04-23 19:57:07 +00:00
|
|
|
from homeassistant.components.binary_sensor import DEVICE_CLASSES, BinarySensorEntity
|
2022-01-03 10:32:26 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
2018-11-07 11:51:12 +00:00
|
|
|
|
2019-03-21 05:56:46 +00:00
|
|
|
from . import DOMAIN as LUPUSEC_DOMAIN, LupusecDevice
|
2018-11-07 11:51:12 +00:00
|
|
|
|
|
|
|
SCAN_INTERVAL = timedelta(seconds=2)
|
|
|
|
|
|
|
|
|
2022-01-03 10:32:26 +00:00
|
|
|
def setup_platform(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config: ConfigType,
|
|
|
|
add_entities: AddEntitiesCallback,
|
|
|
|
discovery_info: DiscoveryInfoType | None = None,
|
|
|
|
) -> None:
|
2018-11-07 11:51:12 +00:00
|
|
|
"""Set up a sensor for an Lupusec device."""
|
|
|
|
if discovery_info is None:
|
|
|
|
return
|
|
|
|
|
|
|
|
data = hass.data[LUPUSEC_DOMAIN]
|
|
|
|
|
|
|
|
device_types = [CONST.TYPE_OPENING]
|
|
|
|
|
|
|
|
devices = []
|
|
|
|
for device in data.lupusec.get_devices(generic_type=device_types):
|
|
|
|
devices.append(LupusecBinarySensor(data, device))
|
|
|
|
|
|
|
|
add_entities(devices)
|
|
|
|
|
|
|
|
|
2020-04-23 19:57:07 +00:00
|
|
|
class LupusecBinarySensor(LupusecDevice, BinarySensorEntity):
|
2018-11-07 11:51:12 +00:00
|
|
|
"""A binary sensor implementation for Lupusec device."""
|
|
|
|
|
|
|
|
@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."""
|
|
|
|
if self._device.generic_type not in DEVICE_CLASSES:
|
|
|
|
return None
|
|
|
|
return self._device.generic_type
|