Add state class to Flo sensor entities (#70591)

This commit is contained in:
David F. Mulcahey 2022-04-24 18:48:49 -04:00 committed by GitHub
parent e2bbdb26be
commit 31eae0980b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 1 deletions

View file

@ -1,7 +1,11 @@
"""Support for Flo Water Monitor sensors."""
from __future__ import annotations
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity,
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
PERCENTAGE,
@ -65,6 +69,7 @@ class FloDailyUsageSensor(FloEntity, SensorEntity):
_attr_icon = WATER_ICON
_attr_native_unit_of_measurement = VOLUME_GALLONS
_attr_state_class: SensorStateClass = SensorStateClass.TOTAL_INCREASING
def __init__(self, device):
"""Initialize the daily water usage sensor."""
@ -100,6 +105,7 @@ class FloCurrentFlowRateSensor(FloEntity, SensorEntity):
_attr_icon = GAUGE_ICON
_attr_native_unit_of_measurement = "gpm"
_attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT
def __init__(self, device):
"""Initialize the flow rate sensor."""
@ -119,6 +125,7 @@ class FloTemperatureSensor(FloEntity, SensorEntity):
_attr_device_class = SensorDeviceClass.TEMPERATURE
_attr_native_unit_of_measurement = TEMP_FAHRENHEIT
_attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT
def __init__(self, name, device):
"""Initialize the temperature sensor."""
@ -138,6 +145,7 @@ class FloHumiditySensor(FloEntity, SensorEntity):
_attr_device_class = SensorDeviceClass.HUMIDITY
_attr_native_unit_of_measurement = PERCENTAGE
_attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT
def __init__(self, device):
"""Initialize the humidity sensor."""
@ -157,6 +165,7 @@ class FloPressureSensor(FloEntity, SensorEntity):
_attr_device_class = SensorDeviceClass.PRESSURE
_attr_native_unit_of_measurement = PRESSURE_PSI
_attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT
def __init__(self, device):
"""Initialize the pressure sensor."""
@ -176,6 +185,7 @@ class FloBatterySensor(FloEntity, SensorEntity):
_attr_device_class = SensorDeviceClass.BATTERY
_attr_native_unit_of_measurement = PERCENTAGE
_attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT
def __init__(self, device):
"""Initialize the battery sensor."""

View file

@ -1,5 +1,6 @@
"""Test Flo by Moen sensor entities."""
from homeassistant.components.flo.const import DOMAIN as FLO_DOMAIN
from homeassistant.components.sensor import ATTR_STATE_CLASS, SensorStateClass
from homeassistant.const import ATTR_ENTITY_ID, CONF_PASSWORD, CONF_USERNAME
from homeassistant.setup import async_setup_component
@ -18,15 +19,49 @@ async def test_sensors(hass, config_entry, aioclient_mock_fixture):
# we should have 5 entities for the valve
assert hass.states.get("sensor.current_system_mode").state == "home"
assert hass.states.get("sensor.today_s_water_usage").state == "3.7"
assert (
hass.states.get("sensor.today_s_water_usage").attributes[ATTR_STATE_CLASS]
== SensorStateClass.TOTAL_INCREASING
)
assert hass.states.get("sensor.water_flow_rate").state == "0"
assert (
hass.states.get("sensor.water_flow_rate").attributes[ATTR_STATE_CLASS]
== SensorStateClass.MEASUREMENT
)
assert hass.states.get("sensor.water_pressure").state == "54.2"
assert (
hass.states.get("sensor.water_pressure").attributes[ATTR_STATE_CLASS]
== SensorStateClass.MEASUREMENT
)
assert hass.states.get("sensor.water_temperature").state == "21"
assert (
hass.states.get("sensor.water_temperature").attributes[ATTR_STATE_CLASS]
== SensorStateClass.MEASUREMENT
)
# and 3 entities for the detector
assert hass.states.get("sensor.temperature").state == "16"
assert (
hass.states.get("sensor.temperature").attributes[ATTR_STATE_CLASS]
== SensorStateClass.MEASUREMENT
)
assert hass.states.get("sensor.humidity").state == "43"
assert (
hass.states.get("sensor.humidity").attributes[ATTR_STATE_CLASS]
== SensorStateClass.MEASUREMENT
)
assert hass.states.get("sensor.battery").state == "100"
assert (
hass.states.get("sensor.battery").attributes[ATTR_STATE_CLASS]
== SensorStateClass.MEASUREMENT
)
async def test_manual_update_entity(