Add device classes to pool integrations (#84050)

* Add device classes to pool integrations

* Update omnilogic

* Don't use VOLTAGE device class
This commit is contained in:
epenet 2022-12-17 10:06:39 +01:00 committed by GitHub
parent 2d9095263e
commit 768d147cb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 30 deletions

View File

@ -8,7 +8,7 @@ from homeassistant.components.sensor import (
SensorStateClass, SensorStateClass,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ELECTRIC_POTENTIAL_MILLIVOLT, PERCENTAGE, TEMP_CELSIUS from homeassistant.const import PERCENTAGE, UnitOfElectricPotential, UnitOfTemperature
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -19,7 +19,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription( SensorEntityDescription(
key="chlorine", key="chlorine",
name="Chlorine", name="Chlorine",
native_unit_of_measurement=ELECTRIC_POTENTIAL_MILLIVOLT, native_unit_of_measurement=UnitOfElectricPotential.MILLIVOLT,
icon="mdi:pool", icon="mdi:pool",
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
@ -33,7 +33,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
key="temperature", key="temperature",
name="Water Temp", name="Water Temp",
device_class=SensorDeviceClass.TEMPERATURE, device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=TEMP_CELSIUS, native_unit_of_measurement=UnitOfTemperature.CELSIUS,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
SensorEntityDescription( SensorEntityDescription(
@ -44,7 +44,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription( SensorEntityDescription(
key="red_ox", key="red_ox",
name="Red OX", name="Red OX",
native_unit_of_measurement=ELECTRIC_POTENTIAL_MILLIVOLT, native_unit_of_measurement=UnitOfElectricPotential.MILLIVOLT,
icon="mdi:pool", icon="mdi:pool",
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),

View File

@ -5,11 +5,10 @@ from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
CONCENTRATION_PARTS_PER_MILLION, CONCENTRATION_PARTS_PER_MILLION,
ELECTRIC_POTENTIAL_MILLIVOLT,
PERCENTAGE, PERCENTAGE,
TEMP_CELSIUS, UnitOfElectricPotential,
TEMP_FAHRENHEIT,
UnitOfMass, UnitOfMass,
UnitOfTemperature,
UnitOfVolume, UnitOfVolume,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -108,12 +107,12 @@ class OmniLogicTemperatureSensor(OmnilogicSensor):
sensor_data = self.coordinator.data[self._item_id][self._state_key] sensor_data = self.coordinator.data[self._item_id][self._state_key]
hayward_state = sensor_data hayward_state = sensor_data
hayward_unit_of_measure = TEMP_FAHRENHEIT hayward_unit_of_measure = UnitOfTemperature.FAHRENHEIT
state = sensor_data state = sensor_data
if self._unit_type == "Metric": if self._unit_type == "Metric":
hayward_state = round((int(hayward_state) - 32) * 5 / 9, 1) hayward_state = round((int(hayward_state) - 32) * 5 / 9, 1)
hayward_unit_of_measure = TEMP_CELSIUS hayward_unit_of_measure = UnitOfTemperature.CELSIUS
if int(sensor_data) == -1: if int(sensor_data) == -1:
hayward_state = None hayward_state = None
@ -122,7 +121,7 @@ class OmniLogicTemperatureSensor(OmnilogicSensor):
self._attrs["hayward_temperature"] = hayward_state self._attrs["hayward_temperature"] = hayward_state
self._attrs["hayward_unit_of_measure"] = hayward_unit_of_measure self._attrs["hayward_unit_of_measure"] = hayward_unit_of_measure
self._unit = TEMP_FAHRENHEIT self._unit = UnitOfTemperature.FAHRENHEIT
return state return state
@ -259,7 +258,7 @@ SENSOR_TYPES: dict[tuple[int, str], list[dict[str, Any]]] = {
"kind": "air_temperature", "kind": "air_temperature",
"device_class": SensorDeviceClass.TEMPERATURE, "device_class": SensorDeviceClass.TEMPERATURE,
"icon": None, "icon": None,
"unit": TEMP_FAHRENHEIT, "unit": UnitOfTemperature.FAHRENHEIT,
"guard_condition": [{}], "guard_condition": [{}],
}, },
], ],
@ -270,7 +269,7 @@ SENSOR_TYPES: dict[tuple[int, str], list[dict[str, Any]]] = {
"kind": "water_temperature", "kind": "water_temperature",
"device_class": SensorDeviceClass.TEMPERATURE, "device_class": SensorDeviceClass.TEMPERATURE,
"icon": None, "icon": None,
"unit": TEMP_FAHRENHEIT, "unit": UnitOfTemperature.FAHRENHEIT,
"guard_condition": [{}], "guard_condition": [{}],
}, },
], ],
@ -351,7 +350,7 @@ SENSOR_TYPES: dict[tuple[int, str], list[dict[str, Any]]] = {
"kind": "csad_orp", "kind": "csad_orp",
"device_class": None, "device_class": None,
"icon": "mdi:gauge", "icon": "mdi:gauge",
"unit": ELECTRIC_POTENTIAL_MILLIVOLT, "unit": UnitOfElectricPotential.MILLIVOLT,
"guard_condition": [ "guard_condition": [
{"orp": ""}, {"orp": ""},
], ],

View File

@ -15,9 +15,9 @@ from homeassistant.components.sensor import (
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
CONCENTRATION_PARTS_PER_MILLION, CONCENTRATION_PARTS_PER_MILLION,
ELECTRIC_POTENTIAL_MILLIVOLT,
PERCENTAGE, PERCENTAGE,
TEMP_CELSIUS, UnitOfElectricPotential,
UnitOfTemperature,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity import DeviceInfo
@ -34,24 +34,21 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription( SensorEntityDescription(
key="temperature", key="temperature",
name="Temperature", name="Temperature",
native_unit_of_measurement=TEMP_CELSIUS, native_unit_of_measurement=UnitOfTemperature.CELSIUS,
icon=None,
device_class=SensorDeviceClass.TEMPERATURE, device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
SensorEntityDescription( SensorEntityDescription(
key="orp", key="orp",
name="Oxydo Reduction Potential", name="Oxydo Reduction Potential",
native_unit_of_measurement=ELECTRIC_POTENTIAL_MILLIVOLT, native_unit_of_measurement=UnitOfElectricPotential.MILLIVOLT,
icon="mdi:pool", icon="mdi:pool",
device_class=None,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
SensorEntityDescription( SensorEntityDescription(
key="ph", key="ph",
name="pH", name="pH",
icon="mdi:pool", icon="mdi:pool",
device_class=None,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
SensorEntityDescription( SensorEntityDescription(
@ -59,14 +56,12 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
name="TDS", name="TDS",
native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION, native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
icon="mdi:pool", icon="mdi:pool",
device_class=None,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
SensorEntityDescription( SensorEntityDescription(
key="battery", key="battery",
name="Battery", name="Battery",
native_unit_of_measurement=PERCENTAGE, native_unit_of_measurement=PERCENTAGE,
icon=None,
device_class=SensorDeviceClass.BATTERY, device_class=SensorDeviceClass.BATTERY,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
@ -74,7 +69,6 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
key="rssi", key="rssi",
name="RSSI", name="RSSI",
native_unit_of_measurement=PERCENTAGE, native_unit_of_measurement=PERCENTAGE,
icon=None,
device_class=SensorDeviceClass.SIGNAL_STRENGTH, device_class=SensorDeviceClass.SIGNAL_STRENGTH,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
@ -83,7 +77,6 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
name="Salt", name="Salt",
native_unit_of_measurement="mg/L", native_unit_of_measurement="mg/L",
icon="mdi:pool", icon="mdi:pool",
device_class=None,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
) )

View File

@ -9,9 +9,9 @@ from homeassistant.components.sensor import (
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
CONF_EMAIL, CONF_EMAIL,
ELECTRIC_POTENTIAL_MILLIVOLT,
PERCENTAGE, PERCENTAGE,
TEMP_CELSIUS, UnitOfElectricPotential,
UnitOfTemperature,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -22,7 +22,7 @@ from .const import DOMAIN
SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription( SensorEntityDescription(
key="Chlorine", key="Chlorine",
native_unit_of_measurement=ELECTRIC_POTENTIAL_MILLIVOLT, native_unit_of_measurement=UnitOfElectricPotential.MILLIVOLT,
icon="mdi:pool", icon="mdi:pool",
name="Chlorine", name="Chlorine",
), ),
@ -39,7 +39,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
), ),
SensorEntityDescription( SensorEntityDescription(
key="Water Temp", key="Water Temp",
native_unit_of_measurement=TEMP_CELSIUS, native_unit_of_measurement=UnitOfTemperature.CELSIUS,
icon="mdi:coolant-temperature", icon="mdi:coolant-temperature",
name="Temperature", name="Temperature",
device_class=SensorDeviceClass.TEMPERATURE, device_class=SensorDeviceClass.TEMPERATURE,
@ -52,13 +52,13 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
), ),
SensorEntityDescription( SensorEntityDescription(
key="Chlorine High", key="Chlorine High",
native_unit_of_measurement=ELECTRIC_POTENTIAL_MILLIVOLT, native_unit_of_measurement=UnitOfElectricPotential.MILLIVOLT,
icon="mdi:pool", icon="mdi:pool",
name="Chlorine High", name="Chlorine High",
), ),
SensorEntityDescription( SensorEntityDescription(
key="Chlorine Low", key="Chlorine Low",
native_unit_of_measurement=ELECTRIC_POTENTIAL_MILLIVOLT, native_unit_of_measurement=UnitOfElectricPotential.MILLIVOLT,
icon="mdi:pool", icon="mdi:pool",
name="Chlorine Low", name="Chlorine Low",
), ),