Home Assistant Unofficial Reference 2024.12.1
binary_sensor.py
Go to the documentation of this file.
1 """Checking binary status values from your ROMY."""
2 
4  BinarySensorDeviceClass,
5  BinarySensorEntity,
6  BinarySensorEntityDescription,
7 )
8 from homeassistant.config_entries import ConfigEntry
9 from homeassistant.core import HomeAssistant
10 from homeassistant.helpers.entity_platform import AddEntitiesCallback
11 
12 from .const import DOMAIN
13 from .coordinator import RomyVacuumCoordinator
14 from .entity import RomyEntity
15 
16 BINARY_SENSORS: list[BinarySensorEntityDescription] = [
18  key="dustbin",
19  translation_key="dustbin_present",
20  ),
22  key="dock",
23  translation_key="docked",
24  device_class=BinarySensorDeviceClass.PLUG,
25  ),
27  key="water_tank",
28  translation_key="water_tank_present",
29  device_class=BinarySensorDeviceClass.MOISTURE,
30  ),
32  key="water_tank_empty",
33  translation_key="water_tank_empty",
34  device_class=BinarySensorDeviceClass.PROBLEM,
35  ),
36 ]
37 
38 
40  hass: HomeAssistant,
41  config_entry: ConfigEntry,
42  async_add_entities: AddEntitiesCallback,
43 ) -> None:
44  """Set up ROMY vacuum cleaner."""
45 
46  coordinator: RomyVacuumCoordinator = hass.data[DOMAIN][config_entry.entry_id]
47 
49  RomyBinarySensor(coordinator, entity_description)
50  for entity_description in BINARY_SENSORS
51  if entity_description.key in coordinator.romy.binary_sensors
52  )
53 
54 
56  """RomyBinarySensor Class."""
57 
58  entity_description: BinarySensorEntityDescription
59 
60  def __init__(
61  self,
62  coordinator: RomyVacuumCoordinator,
63  entity_description: BinarySensorEntityDescription,
64  ) -> None:
65  """Initialize the RomyBinarySensor."""
66  super().__init__(coordinator)
67  self._attr_unique_id_attr_unique_id = f"{entity_description.key}_{self.romy.unique_id}"
68  self.entity_descriptionentity_description = entity_description
69 
70  @property
71  def is_on(self) -> bool:
72  """Return the value of the sensor."""
73  return bool(self.romyromyromy.binary_sensors[self.entity_descriptionentity_description.key])
None __init__(self, RomyVacuumCoordinator coordinator, BinarySensorEntityDescription entity_description)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)