From f3e05534eed2be0aa43ce766133adc9586ab1977 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 5 Oct 2022 00:49:54 +0200 Subject: [PATCH] Use VOLUME device_class in flume (#79585) --- homeassistant/components/flume/const.py | 38 ------------------ homeassistant/components/flume/sensor.py | 49 +++++++++++++++++++++++- 2 files changed, 47 insertions(+), 40 deletions(-) diff --git a/homeassistant/components/flume/const.py b/homeassistant/components/flume/const.py index 5e095961ed8..656c2eb1018 100644 --- a/homeassistant/components/flume/const.py +++ b/homeassistant/components/flume/const.py @@ -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" diff --git a/homeassistant/components/flume/sensor.py b/homeassistant/components/flume/sensor.py index 6d68058732d..51d1b54bee8 100644 --- a/homeassistant/components/flume/sensor.py +++ b/homeassistant/components/flume/sensor.py @@ -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,