Home Assistant Unofficial Reference 2024.12.1
binary_sensor.py
Go to the documentation of this file.
1 """Fully Kiosk Browser sensor."""
2 
3 from __future__ import annotations
4 
6  BinarySensorDeviceClass,
7  BinarySensorEntity,
8  BinarySensorEntityDescription,
9 )
10 from homeassistant.const import EntityCategory
11 from homeassistant.core import HomeAssistant
12 from homeassistant.helpers.entity_platform import AddEntitiesCallback
13 
14 from . import FullyKioskConfigEntry
15 from .coordinator import FullyKioskDataUpdateCoordinator
16 from .entity import FullyKioskEntity
17 
18 SENSORS: tuple[BinarySensorEntityDescription, ...] = (
20  key="kioskMode",
21  translation_key="kiosk_mode",
22  entity_category=EntityCategory.DIAGNOSTIC,
23  ),
25  key="plugged",
26  translation_key="plugged_in",
27  device_class=BinarySensorDeviceClass.PLUG,
28  entity_category=EntityCategory.DIAGNOSTIC,
29  ),
31  key="isDeviceAdmin",
32  translation_key="device_admin",
33  entity_category=EntityCategory.DIAGNOSTIC,
34  ),
35 )
36 
37 
39  hass: HomeAssistant,
40  config_entry: FullyKioskConfigEntry,
41  async_add_entities: AddEntitiesCallback,
42 ) -> None:
43  """Set up the Fully Kiosk Browser sensor."""
44  coordinator = config_entry.runtime_data
45 
47  FullyBinarySensor(coordinator, description)
48  for description in SENSORS
49  if description.key in coordinator.data
50  )
51 
52 
54  """Representation of a Fully Kiosk Browser binary sensor."""
55 
56  def __init__(
57  self,
58  coordinator: FullyKioskDataUpdateCoordinator,
59  description: BinarySensorEntityDescription,
60  ) -> None:
61  """Initialize the binary sensor."""
62  super().__init__(coordinator)
63  self.entity_descriptionentity_description = description
64  self._attr_unique_id_attr_unique_id = f"{coordinator.data['deviceID']}-{description.key}"
65 
66  @property
67  def is_on(self) -> bool | None:
68  """Return if the binary sensor is on."""
69  if (value := self.coordinator.data.get(self.entity_descriptionentity_description.key)) is None:
70  return None
71  return bool(value)
None __init__(self, FullyKioskDataUpdateCoordinator coordinator, BinarySensorEntityDescription description)
None async_setup_entry(HomeAssistant hass, FullyKioskConfigEntry config_entry, AddEntitiesCallback async_add_entities)