1 """Sensors exposing properties of the softener device."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
8 from aioaquacell
import Softener
13 SensorEntityDescription,
21 from .
import AquacellConfigEntry
22 from .coordinator
import AquacellCoordinator
23 from .entity
import AquacellEntity
28 @dataclass(frozen=True, kw_only=True)
30 """Describes Softener sensor entity."""
32 value_fn: Callable[[Softener], StateType]
35 SENSORS: tuple[SoftenerSensorEntityDescription, ...] = (
37 key=
"salt_left_side_percentage",
38 translation_key=
"salt_left_side_percentage",
39 state_class=SensorStateClass.MEASUREMENT,
40 native_unit_of_measurement=PERCENTAGE,
41 value_fn=
lambda softener: softener.salt.leftPercent,
44 key=
"salt_right_side_percentage",
45 translation_key=
"salt_right_side_percentage",
46 state_class=SensorStateClass.MEASUREMENT,
47 native_unit_of_measurement=PERCENTAGE,
48 value_fn=
lambda softener: softener.salt.rightPercent,
51 key=
"salt_left_side_time_remaining",
52 translation_key=
"salt_left_side_time_remaining",
53 device_class=SensorDeviceClass.DURATION,
54 native_unit_of_measurement=UnitOfTime.DAYS,
55 value_fn=
lambda softener: softener.salt.leftDays,
58 key=
"salt_right_side_time_remaining",
59 translation_key=
"salt_right_side_time_remaining",
60 device_class=SensorDeviceClass.DURATION,
61 native_unit_of_measurement=UnitOfTime.DAYS,
62 value_fn=
lambda softener: softener.salt.rightDays,
66 device_class=SensorDeviceClass.BATTERY,
67 native_unit_of_measurement=PERCENTAGE,
68 value_fn=
lambda softener: softener.battery,
72 translation_key=
"wi_fi_strength",
73 value_fn=
lambda softener: softener.wifiLevel,
74 device_class=SensorDeviceClass.ENUM,
86 config_entry: AquacellConfigEntry,
87 async_add_entities: AddEntitiesCallback,
89 """Set up the sensors."""
90 softeners = config_entry.runtime_data.data
94 for softener_key
in softeners
99 """Softener sensor."""
101 entity_description: SoftenerSensorEntityDescription
105 coordinator: AquacellCoordinator,
106 description: SoftenerSensorEntityDescription,
109 """Pass coordinator to CoordinatorEntity."""
110 super().
__init__(coordinator, softener_key, description.key)
116 """Return the state of the sensor."""
StateType native_value(self)
None __init__(self, AquacellCoordinator coordinator, SoftenerSensorEntityDescription description, str softener_key)
None async_setup_entry(HomeAssistant hass, AquacellConfigEntry config_entry, AddEntitiesCallback async_add_entities)