2020-07-01 05:44:10 +00:00
|
|
|
"""Sensor platform for the PoolSense sensor."""
|
2024-03-08 14:04:07 +00:00
|
|
|
|
2021-09-06 09:58:47 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2021-12-16 16:06:16 +00:00
|
|
|
from homeassistant.components.sensor import (
|
|
|
|
SensorDeviceClass,
|
|
|
|
SensorEntity,
|
|
|
|
SensorEntityDescription,
|
|
|
|
)
|
2024-05-18 11:10:06 +00:00
|
|
|
from homeassistant.const import PERCENTAGE, UnitOfElectricPotential, UnitOfTemperature
|
2022-01-03 18:10:57 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2023-09-27 08:14:51 +00:00
|
|
|
from homeassistant.helpers.typing import StateType
|
2020-07-01 05:44:10 +00:00
|
|
|
|
2024-05-16 15:31:14 +00:00
|
|
|
from . import PoolSenseConfigEntry
|
2023-09-27 05:04:20 +00:00
|
|
|
from .entity import PoolSenseEntity
|
2020-07-01 05:44:10 +00:00
|
|
|
|
2021-09-06 09:58:47 +00:00
|
|
|
SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
|
|
|
SensorEntityDescription(
|
|
|
|
key="Chlorine",
|
2023-07-22 10:43:51 +00:00
|
|
|
translation_key="chlorine",
|
2022-12-17 09:06:39 +00:00
|
|
|
native_unit_of_measurement=UnitOfElectricPotential.MILLIVOLT,
|
2021-09-06 09:58:47 +00:00
|
|
|
),
|
|
|
|
SensorEntityDescription(
|
|
|
|
key="pH",
|
2023-09-29 17:12:56 +00:00
|
|
|
device_class=SensorDeviceClass.PH,
|
2021-09-06 09:58:47 +00:00
|
|
|
),
|
|
|
|
SensorEntityDescription(
|
|
|
|
key="Battery",
|
|
|
|
native_unit_of_measurement=PERCENTAGE,
|
2021-12-16 16:06:16 +00:00
|
|
|
device_class=SensorDeviceClass.BATTERY,
|
2021-09-06 09:58:47 +00:00
|
|
|
),
|
|
|
|
SensorEntityDescription(
|
|
|
|
key="Water Temp",
|
2022-12-17 09:06:39 +00:00
|
|
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
2024-03-06 11:36:35 +00:00
|
|
|
translation_key="water_temp",
|
2021-12-16 16:06:16 +00:00
|
|
|
device_class=SensorDeviceClass.TEMPERATURE,
|
2021-09-06 09:58:47 +00:00
|
|
|
),
|
|
|
|
SensorEntityDescription(
|
|
|
|
key="Last Seen",
|
2023-07-22 10:43:51 +00:00
|
|
|
translation_key="last_seen",
|
2021-12-16 16:06:16 +00:00
|
|
|
device_class=SensorDeviceClass.TIMESTAMP,
|
2021-09-06 09:58:47 +00:00
|
|
|
),
|
|
|
|
SensorEntityDescription(
|
|
|
|
key="Chlorine High",
|
2023-07-22 10:43:51 +00:00
|
|
|
translation_key="chlorine_high",
|
2022-12-17 09:06:39 +00:00
|
|
|
native_unit_of_measurement=UnitOfElectricPotential.MILLIVOLT,
|
2021-09-06 09:58:47 +00:00
|
|
|
),
|
|
|
|
SensorEntityDescription(
|
|
|
|
key="Chlorine Low",
|
2023-07-22 10:43:51 +00:00
|
|
|
translation_key="chlorine_low",
|
2022-12-17 09:06:39 +00:00
|
|
|
native_unit_of_measurement=UnitOfElectricPotential.MILLIVOLT,
|
2021-09-06 09:58:47 +00:00
|
|
|
),
|
|
|
|
SensorEntityDescription(
|
|
|
|
key="pH High",
|
2023-07-22 10:43:51 +00:00
|
|
|
translation_key="ph_high",
|
2021-09-06 09:58:47 +00:00
|
|
|
),
|
|
|
|
SensorEntityDescription(
|
|
|
|
key="pH Low",
|
2023-07-22 10:43:51 +00:00
|
|
|
translation_key="ph_low",
|
2021-09-06 09:58:47 +00:00
|
|
|
),
|
|
|
|
)
|
2020-07-01 05:44:10 +00:00
|
|
|
|
|
|
|
|
2022-01-03 18:10:57 +00:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant,
|
2024-05-16 15:31:14 +00:00
|
|
|
config_entry: PoolSenseConfigEntry,
|
2022-01-03 18:10:57 +00:00
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
) -> None:
|
2020-07-01 05:44:10 +00:00
|
|
|
"""Defer sensor setup to the shared sensor module."""
|
2024-05-16 15:31:14 +00:00
|
|
|
coordinator = config_entry.runtime_data
|
2020-07-01 05:44:10 +00:00
|
|
|
|
2024-05-18 11:10:06 +00:00
|
|
|
async_add_entities(
|
|
|
|
PoolSenseSensor(coordinator, description) for description in SENSOR_TYPES
|
|
|
|
)
|
2020-07-01 05:44:10 +00:00
|
|
|
|
|
|
|
|
2021-03-22 18:46:46 +00:00
|
|
|
class PoolSenseSensor(PoolSenseEntity, SensorEntity):
|
2020-07-11 02:53:34 +00:00
|
|
|
"""Sensor representing poolsense data."""
|
2020-07-03 22:38:05 +00:00
|
|
|
|
2020-07-01 05:44:10 +00:00
|
|
|
@property
|
2023-09-27 08:14:51 +00:00
|
|
|
def native_value(self) -> StateType:
|
2020-07-01 05:44:10 +00:00
|
|
|
"""State of the sensor."""
|
2021-09-06 09:58:47 +00:00
|
|
|
return self.coordinator.data[self.entity_description.key]
|