Home Assistant Unofficial Reference 2024.12.1
binary_sensor.py
Go to the documentation of this file.
1 """Support for PoolSense binary sensors."""
2 
3 from __future__ import annotations
4 
6  BinarySensorDeviceClass,
7  BinarySensorEntity,
8  BinarySensorEntityDescription,
9 )
10 from homeassistant.core import HomeAssistant
11 from homeassistant.helpers.entity_platform import AddEntitiesCallback
12 
13 from . import PoolSenseConfigEntry
14 from .entity import PoolSenseEntity
15 
16 BINARY_SENSOR_TYPES: tuple[BinarySensorEntityDescription, ...] = (
18  key="pH Status",
19  translation_key="ph_status",
20  device_class=BinarySensorDeviceClass.PROBLEM,
21  ),
23  key="Chlorine Status",
24  translation_key="chlorine_status",
25  device_class=BinarySensorDeviceClass.PROBLEM,
26  ),
27 )
28 
29 
31  hass: HomeAssistant,
32  config_entry: PoolSenseConfigEntry,
33  async_add_entities: AddEntitiesCallback,
34 ) -> None:
35  """Defer sensor setup to the shared sensor module."""
36  coordinator = config_entry.runtime_data
37 
39  PoolSenseBinarySensor(coordinator, description)
40  for description in BINARY_SENSOR_TYPES
41  )
42 
43 
45  """Representation of PoolSense binary sensors."""
46 
47  @property
48  def is_on(self) -> bool:
49  """Return true if the binary sensor is on."""
50  return self.coordinator.data[self.entity_descriptionentity_description.key] == "red"
None async_setup_entry(HomeAssistant hass, PoolSenseConfigEntry config_entry, AddEntitiesCallback async_add_entities)