Use VOLUME device_class in flume (#79585)

This commit is contained in:
epenet 2022-10-05 00:49:54 +02:00 committed by GitHub
parent 253f6616cf
commit f3e05534ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 40 deletions

View File

@ -4,7 +4,6 @@ from __future__ import annotations
from datetime import timedelta
import logging
from homeassistant.components.sensor import SensorEntityDescription
from homeassistant.const import Platform
DOMAIN = "flume"
@ -19,43 +18,6 @@ DEVICE_SCAN_INTERVAL = timedelta(minutes=1)
_LOGGER = logging.getLogger(__package__)
FLUME_TYPE_SENSOR = 2
FLUME_QUERIES_SENSOR: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription(
key="current_interval",
name="Current",
native_unit_of_measurement="gal/m",
),
SensorEntityDescription(
key="month_to_date",
name="Current Month",
native_unit_of_measurement="gal",
),
SensorEntityDescription(
key="week_to_date",
name="Current Week",
native_unit_of_measurement="gal",
),
SensorEntityDescription(
key="today",
name="Current Day",
native_unit_of_measurement="gal",
),
SensorEntityDescription(
key="last_60_min",
name="60 Minutes",
native_unit_of_measurement="gal/h",
),
SensorEntityDescription(
key="last_24_hrs",
name="24 Hours",
native_unit_of_measurement="gal/d",
),
SensorEntityDescription(
key="last_30_days",
name="30 Days",
native_unit_of_measurement="gal/mo",
),
)
FLUME_AUTH = "flume_auth"
FLUME_HTTP_SESSION = "http_session"

View File

@ -3,8 +3,13 @@ from numbers import Number
from pyflume import FlumeData
from homeassistant.components.sensor import SensorEntity, SensorEntityDescription
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import VOLUME_GALLONS
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -14,7 +19,6 @@ from .const import (
FLUME_AUTH,
FLUME_DEVICES,
FLUME_HTTP_SESSION,
FLUME_QUERIES_SENSOR,
FLUME_TYPE_SENSOR,
KEY_DEVICE_ID,
KEY_DEVICE_LOCATION,
@ -24,6 +28,47 @@ from .const import (
from .coordinator import FlumeDeviceDataUpdateCoordinator
from .entity import FlumeEntity
FLUME_QUERIES_SENSOR: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription(
key="current_interval",
name="Current",
native_unit_of_measurement=f"{VOLUME_GALLONS}/m",
),
SensorEntityDescription(
key="month_to_date",
name="Current Month",
native_unit_of_measurement=VOLUME_GALLONS,
device_class=SensorDeviceClass.VOLUME,
),
SensorEntityDescription(
key="week_to_date",
name="Current Week",
native_unit_of_measurement=VOLUME_GALLONS,
device_class=SensorDeviceClass.VOLUME,
),
SensorEntityDescription(
key="today",
name="Current Day",
native_unit_of_measurement=VOLUME_GALLONS,
device_class=SensorDeviceClass.VOLUME,
),
SensorEntityDescription(
key="last_60_min",
name="60 Minutes",
native_unit_of_measurement=f"{VOLUME_GALLONS}/h",
),
SensorEntityDescription(
key="last_24_hrs",
name="24 Hours",
native_unit_of_measurement=f"{VOLUME_GALLONS}/d",
),
SensorEntityDescription(
key="last_30_days",
name="30 Days",
native_unit_of_measurement=f"{VOLUME_GALLONS}/mo",
),
)
async def async_setup_entry(
hass: HomeAssistant,