Home Assistant Unofficial Reference 2024.12.1
sensor.py
Go to the documentation of this file.
1 """Sensor platform for the PoolSense sensor."""
2 
3 from __future__ import annotations
4 
6  SensorDeviceClass,
7  SensorEntity,
8  SensorEntityDescription,
9 )
10 from homeassistant.const import PERCENTAGE, UnitOfElectricPotential, UnitOfTemperature
11 from homeassistant.core import HomeAssistant
12 from homeassistant.helpers.entity_platform import AddEntitiesCallback
13 from homeassistant.helpers.typing import StateType
14 
15 from . import PoolSenseConfigEntry
16 from .entity import PoolSenseEntity
17 
18 SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
20  key="Chlorine",
21  translation_key="chlorine",
22  native_unit_of_measurement=UnitOfElectricPotential.MILLIVOLT,
23  ),
25  key="pH",
26  device_class=SensorDeviceClass.PH,
27  ),
29  key="Battery",
30  native_unit_of_measurement=PERCENTAGE,
31  device_class=SensorDeviceClass.BATTERY,
32  ),
34  key="Water Temp",
35  native_unit_of_measurement=UnitOfTemperature.CELSIUS,
36  translation_key="water_temp",
37  device_class=SensorDeviceClass.TEMPERATURE,
38  ),
40  key="Last Seen",
41  translation_key="last_seen",
42  device_class=SensorDeviceClass.TIMESTAMP,
43  ),
45  key="Chlorine High",
46  translation_key="chlorine_high",
47  native_unit_of_measurement=UnitOfElectricPotential.MILLIVOLT,
48  ),
50  key="Chlorine Low",
51  translation_key="chlorine_low",
52  native_unit_of_measurement=UnitOfElectricPotential.MILLIVOLT,
53  ),
55  key="pH High",
56  translation_key="ph_high",
57  ),
59  key="pH Low",
60  translation_key="ph_low",
61  ),
62 )
63 
64 
66  hass: HomeAssistant,
67  config_entry: PoolSenseConfigEntry,
68  async_add_entities: AddEntitiesCallback,
69 ) -> None:
70  """Defer sensor setup to the shared sensor module."""
71  coordinator = config_entry.runtime_data
72 
74  PoolSenseSensor(coordinator, description) for description in SENSOR_TYPES
75  )
76 
77 
79  """Sensor representing poolsense data."""
80 
81  @property
82  def native_value(self) -> StateType:
83  """State of the sensor."""
84  return self.coordinator.data[self.entity_descriptionentity_description.key]
None async_setup_entry(HomeAssistant hass, PoolSenseConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: sensor.py:69