Home Assistant Unofficial Reference 2024.12.1
binary_sensor.py
Go to the documentation of this file.
1 """Support for Lupusec Security System binary sensors."""
2 
3 from __future__ import annotations
4 
5 from datetime import timedelta
6 from functools import partial
7 import logging
8 
9 import lupupy.constants as CONST
10 
12  BinarySensorDeviceClass,
13  BinarySensorEntity,
14 )
15 from homeassistant.config_entries import ConfigEntry
16 from homeassistant.core import HomeAssistant
17 from homeassistant.helpers.entity_platform import AddEntitiesCallback
18 
19 from . import DOMAIN
20 from .entity import LupusecBaseSensor
21 
22 SCAN_INTERVAL = timedelta(seconds=2)
23 
24 _LOGGER = logging.getLogger(__name__)
25 
26 
28  hass: HomeAssistant,
29  config_entry: ConfigEntry,
30  async_add_entities: AddEntitiesCallback,
31 ) -> None:
32  """Set up a binary sensors for a Lupusec device."""
33 
34  data = hass.data[DOMAIN][config_entry.entry_id]
35 
36  device_types = CONST.TYPE_OPENING + CONST.TYPE_SENSOR
37 
38  partial_func = partial(data.get_devices, generic_type=device_types)
39  devices = await hass.async_add_executor_job(partial_func)
40 
42  LupusecBinarySensor(device, config_entry.entry_id) for device in devices
43  )
44 
45 
47  """A binary sensor implementation for Lupusec device."""
48 
49  _attr_name = None
50 
51  @property
52  def is_on(self) -> bool:
53  """Return True if the binary sensor is on."""
54  return self._device_device.is_on
55 
56  @property
57  def device_class(self) -> BinarySensorDeviceClass | None:
58  """Return the class of the binary sensor."""
59  if self._device_device.generic_type not in (
60  item.value for item in BinarySensorDeviceClass
61  ):
62  return None
63  return self._device_device.generic_type
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)