Home Assistant Unofficial Reference 2024.12.1
binary_sensor.py
Go to the documentation of this file.
1 """Binary sensor support for the Skybell HD Doorbell."""
2 
3 from __future__ import annotations
4 
5 from aioskybell.helpers import const as CONST
6 
8  BinarySensorDeviceClass,
9  BinarySensorEntity,
10  BinarySensorEntityDescription,
11 )
12 from homeassistant.config_entries import ConfigEntry
13 from homeassistant.core import HomeAssistant, callback
14 from homeassistant.helpers.entity_platform import AddEntitiesCallback
15 
16 from . import DOMAIN
17 from .coordinator import SkybellDataUpdateCoordinator
18 from .entity import SkybellEntity
19 
20 BINARY_SENSOR_TYPES: tuple[BinarySensorEntityDescription, ...] = (
22  key="button",
23  translation_key="button",
24  device_class=BinarySensorDeviceClass.OCCUPANCY,
25  ),
27  key="motion",
28  device_class=BinarySensorDeviceClass.MOTION,
29  ),
30 )
31 
32 
34  hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
35 ) -> None:
36  """Set up Skybell binary sensor."""
38  SkybellBinarySensor(coordinator, sensor)
39  for sensor in BINARY_SENSOR_TYPES
40  for coordinator in hass.data[DOMAIN][entry.entry_id]
41  )
42 
43 
45  """A binary sensor implementation for Skybell devices."""
46 
47  def __init__(
48  self,
49  coordinator: SkybellDataUpdateCoordinator,
50  description: BinarySensorEntityDescription,
51  ) -> None:
52  """Initialize a binary sensor for a Skybell device."""
53  super().__init__(coordinator, description)
54  self._event_event: dict[str, str] = {}
55 
56  @callback
57  def _handle_coordinator_update(self) -> None:
58  """Handle updated data from the coordinator."""
59  event = self._device_device.latest(self.entity_descriptionentity_description.key)
60  self._attr_is_on_attr_is_on = bool(event.get(CONST.ID) != self._event_event.get(CONST.ID))
61  self._event_event = event
None __init__(self, SkybellDataUpdateCoordinator coordinator, BinarySensorEntityDescription description)
web.Response get(self, web.Request request, str config_key)
Definition: view.py:88
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)