2020-07-01 05:44:10 +00:00
|
|
|
"""Sensor platform for the PoolSense sensor."""
|
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,
|
|
|
|
)
|
2020-07-01 05:44:10 +00:00
|
|
|
from homeassistant.const import (
|
|
|
|
CONF_EMAIL,
|
2021-07-20 13:57:11 +00:00
|
|
|
ELECTRIC_POTENTIAL_MILLIVOLT,
|
2020-09-05 19:09:14 +00:00
|
|
|
PERCENTAGE,
|
2020-07-01 05:44:10 +00:00
|
|
|
TEMP_CELSIUS,
|
|
|
|
)
|
|
|
|
|
2020-07-11 02:53:34 +00:00
|
|
|
from . import PoolSenseEntity
|
2021-09-06 09:58:47 +00:00
|
|
|
from .const import DOMAIN
|
2020-07-01 05:44:10 +00:00
|
|
|
|
2021-09-06 09:58:47 +00:00
|
|
|
SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
|
|
|
SensorEntityDescription(
|
|
|
|
key="Chlorine",
|
|
|
|
native_unit_of_measurement=ELECTRIC_POTENTIAL_MILLIVOLT,
|
|
|
|
icon="mdi:pool",
|
|
|
|
name="Chlorine",
|
|
|
|
),
|
|
|
|
SensorEntityDescription(
|
|
|
|
key="pH",
|
|
|
|
icon="mdi:pool",
|
|
|
|
name="pH",
|
|
|
|
),
|
|
|
|
SensorEntityDescription(
|
|
|
|
key="Battery",
|
|
|
|
native_unit_of_measurement=PERCENTAGE,
|
|
|
|
name="Battery",
|
2021-12-16 16:06:16 +00:00
|
|
|
device_class=SensorDeviceClass.BATTERY,
|
2021-09-06 09:58:47 +00:00
|
|
|
),
|
|
|
|
SensorEntityDescription(
|
|
|
|
key="Water Temp",
|
|
|
|
native_unit_of_measurement=TEMP_CELSIUS,
|
|
|
|
icon="mdi:coolant-temperature",
|
|
|
|
name="Temperature",
|
2021-12-16 16:06:16 +00:00
|
|
|
device_class=SensorDeviceClass.TEMPERATURE,
|
2021-09-06 09:58:47 +00:00
|
|
|
),
|
|
|
|
SensorEntityDescription(
|
|
|
|
key="Last Seen",
|
|
|
|
icon="mdi:clock",
|
|
|
|
name="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",
|
|
|
|
native_unit_of_measurement=ELECTRIC_POTENTIAL_MILLIVOLT,
|
|
|
|
icon="mdi:pool",
|
|
|
|
name="Chlorine High",
|
|
|
|
),
|
|
|
|
SensorEntityDescription(
|
|
|
|
key="Chlorine Low",
|
|
|
|
native_unit_of_measurement=ELECTRIC_POTENTIAL_MILLIVOLT,
|
|
|
|
icon="mdi:pool",
|
|
|
|
name="Chlorine Low",
|
|
|
|
),
|
|
|
|
SensorEntityDescription(
|
|
|
|
key="pH High",
|
|
|
|
icon="mdi:pool",
|
|
|
|
name="pH High",
|
|
|
|
),
|
|
|
|
SensorEntityDescription(
|
|
|
|
key="pH Low",
|
|
|
|
icon="mdi:pool",
|
|
|
|
name="pH Low",
|
|
|
|
),
|
|
|
|
)
|
2020-07-01 05:44:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
|
|
|
"""Defer sensor setup to the shared sensor module."""
|
|
|
|
coordinator = hass.data[DOMAIN][config_entry.entry_id]
|
|
|
|
|
2021-09-06 09:58:47 +00:00
|
|
|
entities = [
|
|
|
|
PoolSenseSensor(coordinator, config_entry.data[CONF_EMAIL], description)
|
|
|
|
for description in SENSOR_TYPES
|
|
|
|
]
|
2020-07-01 05:44:10 +00:00
|
|
|
|
2021-09-06 09:58:47 +00:00
|
|
|
async_add_entities(entities, False)
|
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
|
2021-08-12 11:26:17 +00:00
|
|
|
def native_value(self):
|
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]
|