Home Assistant Unofficial Reference 2024.12.1
sensor.py
Go to the documentation of this file.
1 """Sensor platform for the Flipr's pool_sensor."""
2 
3 from __future__ import annotations
4 
6  SensorDeviceClass,
7  SensorEntity,
8  SensorEntityDescription,
9  SensorStateClass,
10 )
11 from homeassistant.const import PERCENTAGE, UnitOfElectricPotential, UnitOfTemperature
12 from homeassistant.core import HomeAssistant
13 from homeassistant.helpers.entity_platform import AddEntitiesCallback
14 
15 from . import FliprConfigEntry
16 from .entity import FliprEntity
17 
18 SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
20  key="chlorine",
21  translation_key="chlorine",
22  native_unit_of_measurement=UnitOfElectricPotential.MILLIVOLT,
23  state_class=SensorStateClass.MEASUREMENT,
24  ),
26  key="ph",
27  device_class=SensorDeviceClass.PH,
28  state_class=SensorStateClass.MEASUREMENT,
29  ),
31  key="temperature",
32  translation_key="water_temperature",
33  device_class=SensorDeviceClass.TEMPERATURE,
34  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
35  state_class=SensorStateClass.MEASUREMENT,
36  ),
38  key="date_time",
39  translation_key="last_measured",
40  device_class=SensorDeviceClass.TIMESTAMP,
41  ),
43  key="red_ox",
44  translation_key="red_ox",
45  native_unit_of_measurement=UnitOfElectricPotential.MILLIVOLT,
46  state_class=SensorStateClass.MEASUREMENT,
47  ),
49  key="battery",
50  native_unit_of_measurement=PERCENTAGE,
51  state_class=SensorStateClass.MEASUREMENT,
52  device_class=SensorDeviceClass.BATTERY,
53  ),
54 )
55 
56 
58  hass: HomeAssistant,
59  config_entry: FliprConfigEntry,
60  async_add_entities: AddEntitiesCallback,
61 ) -> None:
62  """Defer sensor setup to the shared sensor module."""
63  coordinators = config_entry.runtime_data.flipr_coordinators
64 
66  FliprSensor(coordinator, description)
67  for description in SENSOR_TYPES
68  for coordinator in coordinators
69  )
70 
71 
73  """Sensor representing FliprSensor data."""
74 
75  @property
76  def native_value(self) -> str:
77  """State of the sensor."""
78  return self.coordinator.data[self.entity_descriptionentity_description.key]
None async_setup_entry(HomeAssistant hass, FliprConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: sensor.py:61