1 """Support for DROP binary sensors."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
10 BinarySensorDeviceClass,
12 BinarySensorEntityDescription,
30 from .coordinator
import DROPDeviceDataUpdateCoordinator
31 from .entity
import DROPEntity
33 _LOGGER = logging.getLogger(__name__)
37 ALERT_SENSOR =
"alert_sensor"
38 LEAK_DETECTED =
"leak"
39 PENDING_NOTIFICATION =
"pending_notification"
42 RESERVE_IN_USE =
"reserve_in_use"
46 @dataclass(kw_only=True, frozen=True)
48 """Describes DROP binary sensor entity."""
50 value_fn: Callable[[DROPDeviceDataUpdateCoordinator], int |
None]
53 BINARY_SENSORS: list[DROPBinarySensorEntityDescription] = [
56 translation_key=LEAK_DETECTED,
57 device_class=BinarySensorDeviceClass.MOISTURE,
58 value_fn=
lambda device: device.drop_api.leak_detected(),
61 key=PENDING_NOTIFICATION,
62 translation_key=PENDING_NOTIFICATION,
63 value_fn=
lambda device: device.drop_api.notification_pending(),
67 translation_key=SALT_LOW,
68 value_fn=
lambda device: device.drop_api.salt_low(),
72 translation_key=RESERVE_IN_USE,
73 value_fn=
lambda device: device.drop_api.reserve_in_use(),
77 translation_key=PUMP_STATUS,
78 value_fn=
lambda device: device.drop_api.pump_status(),
82 translation_key=ALERT_SENSOR,
83 device_class=BinarySensorDeviceClass.PROBLEM,
84 value_fn=
lambda device: device.drop_api.sensor_high(),
89 device_class=BinarySensorDeviceClass.POWER,
90 value_fn=
lambda device: device.drop_api.power(),
95 DEVICE_BINARY_SENSORS: dict[str, list[str]] = {
96 DEV_ALERT: [ALERT_SENSOR, POWER],
97 DEV_HUB: [LEAK_DETECTED, PENDING_NOTIFICATION],
98 DEV_LEAK_DETECTOR: [LEAK_DETECTED],
99 DEV_PROTECTION_VALVE: [LEAK_DETECTED],
100 DEV_PUMP_CONTROLLER: [LEAK_DETECTED, PUMP_STATUS],
101 DEV_RO_FILTER: [LEAK_DETECTED],
102 DEV_SALT_SENSOR: [SALT_LOW],
103 DEV_SOFTENER: [RESERVE_IN_USE],
109 config_entry: ConfigEntry,
110 async_add_entities: AddEntitiesCallback,
112 """Set up the DROP binary sensors from config entry."""
114 "Set up binary sensor for device type %s with entry_id is %s",
115 config_entry.data[CONF_DEVICE_TYPE],
116 config_entry.entry_id,
119 if config_entry.data[CONF_DEVICE_TYPE]
in DEVICE_BINARY_SENSORS:
122 for sensor
in BINARY_SENSORS
123 if sensor.key
in DEVICE_BINARY_SENSORS[config_entry.data[CONF_DEVICE_TYPE]]
128 """Representation of a DROP binary sensor."""
130 entity_description: DROPBinarySensorEntityDescription
134 coordinator: DROPDeviceDataUpdateCoordinator,
135 entity_description: DROPBinarySensorEntityDescription,
137 """Initialize the binary sensor."""
138 super().
__init__(entity_description.key, coordinator)
143 """Return the state of the binary sensor."""
None __init__(self, DROPDeviceDataUpdateCoordinator coordinator, DROPBinarySensorEntityDescription entity_description)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)