Add state class to Flipr sensors (#73747)

This commit is contained in:
Franck Nijhof 2022-06-20 20:29:50 +02:00 committed by GitHub
parent 66b02ecff0
commit 16e7593a7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -5,6 +5,7 @@ from homeassistant.components.sensor import (
SensorDeviceClass, SensorDeviceClass,
SensorEntity, SensorEntity,
SensorEntityDescription, SensorEntityDescription,
SensorStateClass,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ELECTRIC_POTENTIAL_MILLIVOLT, TEMP_CELSIUS from homeassistant.const import ELECTRIC_POTENTIAL_MILLIVOLT, TEMP_CELSIUS
@ -20,17 +21,20 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
name="Chlorine", name="Chlorine",
native_unit_of_measurement=ELECTRIC_POTENTIAL_MILLIVOLT, native_unit_of_measurement=ELECTRIC_POTENTIAL_MILLIVOLT,
icon="mdi:pool", icon="mdi:pool",
state_class=SensorStateClass.MEASUREMENT,
), ),
SensorEntityDescription( SensorEntityDescription(
key="ph", key="ph",
name="pH", name="pH",
icon="mdi:pool", icon="mdi:pool",
state_class=SensorStateClass.MEASUREMENT,
), ),
SensorEntityDescription( 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=TEMP_CELSIUS,
state_class=SensorStateClass.MEASUREMENT,
), ),
SensorEntityDescription( SensorEntityDescription(
key="date_time", key="date_time",
@ -42,6 +46,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
name="Red OX", name="Red OX",
native_unit_of_measurement=ELECTRIC_POTENTIAL_MILLIVOLT, native_unit_of_measurement=ELECTRIC_POTENTIAL_MILLIVOLT,
icon="mdi:pool", icon="mdi:pool",
state_class=SensorStateClass.MEASUREMENT,
), ),
) )

View File

@ -5,6 +5,7 @@ from unittest.mock import patch
from flipr_api.exceptions import FliprError from flipr_api.exceptions import FliprError
from homeassistant.components.flipr.const import CONF_FLIPR_ID, DOMAIN from homeassistant.components.flipr.const import CONF_FLIPR_ID, DOMAIN
from homeassistant.components.sensor import ATTR_STATE_CLASS, SensorStateClass
from homeassistant.const import ( from homeassistant.const import (
ATTR_ICON, ATTR_ICON,
ATTR_UNIT_OF_MEASUREMENT, ATTR_UNIT_OF_MEASUREMENT,
@ -62,30 +63,35 @@ async def test_sensors(hass: HomeAssistant) -> None:
assert state assert state
assert state.attributes.get(ATTR_ICON) == "mdi:pool" assert state.attributes.get(ATTR_ICON) == "mdi:pool"
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) is None assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) is None
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
assert state.state == "7.03" assert state.state == "7.03"
state = hass.states.get("sensor.flipr_myfliprid_water_temp") state = hass.states.get("sensor.flipr_myfliprid_water_temp")
assert state assert state
assert state.attributes.get(ATTR_ICON) is None assert state.attributes.get(ATTR_ICON) is None
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) is TEMP_CELSIUS assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) is TEMP_CELSIUS
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
assert state.state == "10.5" assert state.state == "10.5"
state = hass.states.get("sensor.flipr_myfliprid_last_measured") state = hass.states.get("sensor.flipr_myfliprid_last_measured")
assert state assert state
assert state.attributes.get(ATTR_ICON) is None assert state.attributes.get(ATTR_ICON) is None
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) is None assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) is None
assert state.attributes.get(ATTR_STATE_CLASS) is None
assert state.state == "2021-02-15T09:10:32+00:00" assert state.state == "2021-02-15T09:10:32+00:00"
state = hass.states.get("sensor.flipr_myfliprid_red_ox") state = hass.states.get("sensor.flipr_myfliprid_red_ox")
assert state assert state
assert state.attributes.get(ATTR_ICON) == "mdi:pool" assert state.attributes.get(ATTR_ICON) == "mdi:pool"
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "mV" assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "mV"
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
assert state.state == "657.58" assert state.state == "657.58"
state = hass.states.get("sensor.flipr_myfliprid_chlorine") state = hass.states.get("sensor.flipr_myfliprid_chlorine")
assert state assert state
assert state.attributes.get(ATTR_ICON) == "mdi:pool" assert state.attributes.get(ATTR_ICON) == "mdi:pool"
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "mV" assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "mV"
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
assert state.state == "0.23654886" assert state.state == "0.23654886"