Home Assistant Unofficial Reference 2024.12.1
binary_sensor.py
Go to the documentation of this file.
1 """Support for Flo Water Monitor binary sensors."""
2 
3 from __future__ import annotations
4 
6  BinarySensorDeviceClass,
7  BinarySensorEntity,
8 )
9 from homeassistant.config_entries import ConfigEntry
10 from homeassistant.core import HomeAssistant
11 from homeassistant.helpers.entity_platform import AddEntitiesCallback
12 
13 from .const import DOMAIN as FLO_DOMAIN
14 from .coordinator import FloDeviceDataUpdateCoordinator
15 from .entity import FloEntity
16 
17 
19  hass: HomeAssistant,
20  config_entry: ConfigEntry,
21  async_add_entities: AddEntitiesCallback,
22 ) -> None:
23  """Set up the Flo sensors from config entry."""
24  devices: list[FloDeviceDataUpdateCoordinator] = hass.data[FLO_DOMAIN][
25  config_entry.entry_id
26  ]["devices"]
27  entities: list[BinarySensorEntity] = []
28  for device in devices:
29  if device.device_type == "puck_oem":
30  # Flo "pucks" (leak detectors) *do* support pending alerts.
31  # However these pending alerts mix unrelated issues like
32  # low-battery alerts, humidity alerts, & temperature alerts
33  # in addition to the critical "water detected" alert.
34  #
35  # Since there are non-binary sensors for battery, humidity,
36  # and temperature, the binary sensor should only cover
37  # water detection. If this sensor trips, you really have
38  # a problem - vs. battery/temp/humidity which are warnings.
39  entities.append(FloWaterDetectedBinarySensor(device))
40  else:
41  entities.append(FloPendingAlertsBinarySensor(device))
42  async_add_entities(entities)
43 
44 
46  """Binary sensor that reports on if there are any pending system alerts."""
47 
48  _attr_device_class = BinarySensorDeviceClass.PROBLEM
49  _attr_translation_key = "pending_system_alerts"
50 
51  def __init__(self, device):
52  """Initialize the pending alerts binary sensor."""
53  super().__init__("pending_system_alerts", device)
54 
55  @property
56  def is_on(self):
57  """Return true if the Flo device has pending alerts."""
58  return self._device.has_alerts
59 
60  @property
62  """Return the state attributes."""
63  if not self._device.has_alerts:
64  return {}
65  return {
66  "info": self._device.pending_info_alerts_count,
67  "warning": self._device.pending_warning_alerts_count,
68  "critical": self._device.pending_critical_alerts_count,
69  }
70 
71 
73  """Binary sensor that reports if water is detected (for leak detectors)."""
74 
75  _attr_device_class = BinarySensorDeviceClass.PROBLEM
76  _attr_translation_key = "water_detected"
77 
78  def __init__(self, device):
79  """Initialize the pending alerts binary sensor."""
80  super().__init__("water_detected", device)
81 
82  @property
83  def is_on(self):
84  """Return true if the Flo device is detecting water."""
85  return self._device.water_detected
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)