1 """Support for DROP sensors."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
12 SensorEntityDescription,
17 CONCENTRATION_PARTS_PER_MILLION,
40 from .coordinator
import DROPDeviceDataUpdateCoordinator
41 from .entity
import DROPEntity
43 _LOGGER = logging.getLogger(__name__)
47 CURRENT_FLOW_RATE =
"current_flow_rate"
48 PEAK_FLOW_RATE =
"peak_flow_rate"
49 WATER_USED_TODAY =
"water_used_today"
50 AVERAGE_WATER_USED =
"average_water_used"
51 CAPACITY_REMAINING =
"capacity_remaining"
52 CURRENT_SYSTEM_PRESSURE =
"current_system_pressure"
53 HIGH_SYSTEM_PRESSURE =
"high_system_pressure"
54 LOW_SYSTEM_PRESSURE =
"low_system_pressure"
56 TEMPERATURE =
"temperature"
57 INLET_TDS =
"inlet_tds"
58 OUTLET_TDS =
"outlet_tds"
59 CARTRIDGE_1_LIFE =
"cart1"
60 CARTRIDGE_2_LIFE =
"cart2"
61 CARTRIDGE_3_LIFE =
"cart3"
64 @dataclass(kw_only=True, frozen=True)
66 """Describes DROP sensor entity."""
68 value_fn: Callable[[DROPDeviceDataUpdateCoordinator], float | int |
None]
71 SENSORS: list[DROPSensorEntityDescription] = [
73 key=CURRENT_FLOW_RATE,
74 translation_key=CURRENT_FLOW_RATE,
75 device_class=SensorDeviceClass.VOLUME_FLOW_RATE,
76 native_unit_of_measurement=UnitOfVolumeFlowRate.GALLONS_PER_MINUTE,
77 suggested_display_precision=1,
78 value_fn=
lambda device: device.drop_api.current_flow_rate(),
79 state_class=SensorStateClass.MEASUREMENT,
83 translation_key=PEAK_FLOW_RATE,
84 device_class=SensorDeviceClass.VOLUME_FLOW_RATE,
85 native_unit_of_measurement=UnitOfVolumeFlowRate.GALLONS_PER_MINUTE,
86 suggested_display_precision=1,
87 value_fn=
lambda device: device.drop_api.peak_flow_rate(),
88 state_class=SensorStateClass.MEASUREMENT,
92 translation_key=WATER_USED_TODAY,
93 device_class=SensorDeviceClass.WATER,
94 native_unit_of_measurement=UnitOfVolume.GALLONS,
95 suggested_display_precision=1,
96 value_fn=
lambda device: device.drop_api.water_used_today(),
97 state_class=SensorStateClass.TOTAL,
100 key=AVERAGE_WATER_USED,
101 translation_key=AVERAGE_WATER_USED,
102 device_class=SensorDeviceClass.WATER,
103 native_unit_of_measurement=UnitOfVolume.GALLONS,
104 suggested_display_precision=0,
105 value_fn=
lambda device: device.drop_api.average_water_used(),
106 state_class=SensorStateClass.TOTAL,
109 key=CAPACITY_REMAINING,
110 translation_key=CAPACITY_REMAINING,
111 device_class=SensorDeviceClass.WATER,
112 native_unit_of_measurement=UnitOfVolume.GALLONS,
113 suggested_display_precision=0,
114 value_fn=
lambda device: device.drop_api.capacity_remaining(),
115 state_class=SensorStateClass.TOTAL,
118 key=CURRENT_SYSTEM_PRESSURE,
119 translation_key=CURRENT_SYSTEM_PRESSURE,
120 device_class=SensorDeviceClass.PRESSURE,
121 native_unit_of_measurement=UnitOfPressure.PSI,
122 suggested_display_precision=1,
123 value_fn=
lambda device: device.drop_api.current_system_pressure(),
124 state_class=SensorStateClass.MEASUREMENT,
127 key=HIGH_SYSTEM_PRESSURE,
128 translation_key=HIGH_SYSTEM_PRESSURE,
129 device_class=SensorDeviceClass.PRESSURE,
130 native_unit_of_measurement=UnitOfPressure.PSI,
131 suggested_display_precision=0,
132 value_fn=
lambda device: device.drop_api.high_system_pressure(),
133 state_class=SensorStateClass.MEASUREMENT,
136 key=LOW_SYSTEM_PRESSURE,
137 translation_key=LOW_SYSTEM_PRESSURE,
138 device_class=SensorDeviceClass.PRESSURE,
139 native_unit_of_measurement=UnitOfPressure.PSI,
140 suggested_display_precision=0,
141 value_fn=
lambda device: device.drop_api.low_system_pressure(),
142 state_class=SensorStateClass.MEASUREMENT,
146 device_class=SensorDeviceClass.BATTERY,
147 native_unit_of_measurement=PERCENTAGE,
148 suggested_display_precision=0,
149 value_fn=
lambda device: device.drop_api.battery(),
150 state_class=SensorStateClass.MEASUREMENT,
151 entity_category=EntityCategory.DIAGNOSTIC,
155 device_class=SensorDeviceClass.TEMPERATURE,
156 native_unit_of_measurement=UnitOfTemperature.FAHRENHEIT,
157 suggested_display_precision=1,
158 value_fn=
lambda device: device.drop_api.temperature(),
159 state_class=SensorStateClass.MEASUREMENT,
163 translation_key=INLET_TDS,
164 native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
165 state_class=SensorStateClass.MEASUREMENT,
166 suggested_display_precision=0,
167 value_fn=
lambda device: device.drop_api.inlet_tds(),
171 translation_key=OUTLET_TDS,
172 native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
173 state_class=SensorStateClass.MEASUREMENT,
174 suggested_display_precision=0,
175 value_fn=
lambda device: device.drop_api.outlet_tds(),
178 key=CARTRIDGE_1_LIFE,
179 translation_key=CARTRIDGE_1_LIFE,
180 native_unit_of_measurement=PERCENTAGE,
181 state_class=SensorStateClass.MEASUREMENT,
182 entity_category=EntityCategory.DIAGNOSTIC,
183 suggested_display_precision=0,
184 value_fn=
lambda device: device.drop_api.cart1(),
187 key=CARTRIDGE_2_LIFE,
188 translation_key=CARTRIDGE_2_LIFE,
189 native_unit_of_measurement=PERCENTAGE,
190 state_class=SensorStateClass.MEASUREMENT,
191 entity_category=EntityCategory.DIAGNOSTIC,
192 suggested_display_precision=0,
193 value_fn=
lambda device: device.drop_api.cart2(),
196 key=CARTRIDGE_3_LIFE,
197 translation_key=CARTRIDGE_3_LIFE,
198 native_unit_of_measurement=PERCENTAGE,
199 state_class=SensorStateClass.MEASUREMENT,
200 entity_category=EntityCategory.DIAGNOSTIC,
201 suggested_display_precision=0,
202 value_fn=
lambda device: device.drop_api.cart3(),
207 DEVICE_SENSORS: dict[str, list[str]] = {
212 CURRENT_SYSTEM_PRESSURE,
213 HIGH_SYSTEM_PRESSURE,
222 CURRENT_SYSTEM_PRESSURE,
224 DEV_FILTER: [BATTERY, CURRENT_FLOW_RATE, CURRENT_SYSTEM_PRESSURE],
225 DEV_LEAK_DETECTOR: [BATTERY, TEMPERATURE],
226 DEV_ALERT: [BATTERY, TEMPERATURE],
227 DEV_PROTECTION_VALVE: [
230 CURRENT_SYSTEM_PRESSURE,
233 DEV_PUMP_CONTROLLER: [CURRENT_FLOW_RATE, CURRENT_SYSTEM_PRESSURE, TEMPERATURE],
246 config_entry: ConfigEntry,
247 async_add_entities: AddEntitiesCallback,
249 """Set up the DROP sensors from config entry."""
251 "Set up sensor for device type %s with entry_id is %s",
252 config_entry.data[CONF_DEVICE_TYPE],
253 config_entry.entry_id,
256 if config_entry.data[CONF_DEVICE_TYPE]
in DEVICE_SENSORS:
258 DROPSensor(hass.data[DOMAIN][config_entry.entry_id], sensor)
259 for sensor
in SENSORS
260 if sensor.key
in DEVICE_SENSORS[config_entry.data[CONF_DEVICE_TYPE]]
265 """Representation of a DROP sensor."""
267 entity_description: DROPSensorEntityDescription
271 coordinator: DROPDeviceDataUpdateCoordinator,
272 entity_description: DROPSensorEntityDescription,
274 """Initialize the sensor."""
275 super().
__init__(entity_description.key, coordinator)
280 """Return the value reported by the sensor."""
None __init__(self, DROPDeviceDataUpdateCoordinator coordinator, DROPSensorEntityDescription entity_description)
float|int|None native_value(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)