Add matching class for number

This commit is contained in:
Joakim Plate
2023-12-19 21:09:41 +01:00
parent fbc13bfe02
commit 398c9c8116
2 changed files with 19 additions and 1 deletions

View File

@@ -34,6 +34,7 @@ from homeassistant.const import (
UnitOfTemperature, UnitOfTemperature,
UnitOfTime, UnitOfTime,
UnitOfVolume, UnitOfVolume,
UnitOfVolumeFlowRate,
UnitOfVolumetricFlux, UnitOfVolumetricFlux,
) )
from homeassistant.helpers.deprecation import ( from homeassistant.helpers.deprecation import (
@@ -42,7 +43,11 @@ from homeassistant.helpers.deprecation import (
check_if_deprecated_constant, check_if_deprecated_constant,
dir_with_deprecated_constants, dir_with_deprecated_constants,
) )
from homeassistant.util.unit_conversion import BaseUnitConverter, TemperatureConverter from homeassistant.util.unit_conversion import (
BaseUnitConverter,
TemperatureConverter,
VolumeFlowRateConverter,
)
ATTR_VALUE = "value" ATTR_VALUE = "value"
ATTR_MIN = "min" ATTR_MIN = "min"
@@ -372,6 +377,14 @@ class NumberDeviceClass(StrEnum):
USCS/imperial units are currently assumed to be US volumes) USCS/imperial units are currently assumed to be US volumes)
""" """
VOLUME_FLOW_RATE = "volume_flow_rate"
"""Generic flow rate
Unit of measurement: UnitOfVolumeFlowRate
- SI / metric: `m³/h`, `L/min`
- USCS / imperial: `ft³/min`, `gal/min`
"""
WATER = "water" WATER = "water"
"""Water. """Water.
@@ -464,6 +477,7 @@ DEVICE_CLASS_UNITS: dict[NumberDeviceClass, set[type[StrEnum] | str | None]] = {
NumberDeviceClass.VOLTAGE: set(UnitOfElectricPotential), NumberDeviceClass.VOLTAGE: set(UnitOfElectricPotential),
NumberDeviceClass.VOLUME: set(UnitOfVolume), NumberDeviceClass.VOLUME: set(UnitOfVolume),
NumberDeviceClass.VOLUME_STORAGE: set(UnitOfVolume), NumberDeviceClass.VOLUME_STORAGE: set(UnitOfVolume),
NumberDeviceClass.VOLUME_FLOW_RATE: set(UnitOfVolumeFlowRate),
NumberDeviceClass.WATER: { NumberDeviceClass.WATER: {
UnitOfVolume.CENTUM_CUBIC_FEET, UnitOfVolume.CENTUM_CUBIC_FEET,
UnitOfVolume.CUBIC_FEET, UnitOfVolume.CUBIC_FEET,
@@ -477,6 +491,7 @@ DEVICE_CLASS_UNITS: dict[NumberDeviceClass, set[type[StrEnum] | str | None]] = {
UNIT_CONVERTERS: dict[str, type[BaseUnitConverter]] = { UNIT_CONVERTERS: dict[str, type[BaseUnitConverter]] = {
NumberDeviceClass.TEMPERATURE: TemperatureConverter, NumberDeviceClass.TEMPERATURE: TemperatureConverter,
NumberDeviceClass.VOLUME_FLOW_RATE: VolumeFlowRateConverter,
} }
# These can be removed if no deprecated constant are in this module anymore # These can be removed if no deprecated constant are in this module anymore

View File

@@ -148,6 +148,9 @@
"volume_storage": { "volume_storage": {
"name": "[%key:component::sensor::entity_component::volume_storage::name%]" "name": "[%key:component::sensor::entity_component::volume_storage::name%]"
}, },
"volume_flow_rate": {
"name": "[%key:component::sensor::entity_component::volume_flow_rate::name%]"
},
"water": { "water": {
"name": "[%key:component::sensor::entity_component::water::name%]" "name": "[%key:component::sensor::entity_component::water::name%]"
}, },