parent
ac3711e6ab
commit
ca28006d76
|
@ -296,7 +296,7 @@ class NumberDeviceClass(StrEnum):
|
|||
VOLTAGE = "voltage"
|
||||
"""Voltage.
|
||||
|
||||
Unit of measurement: `V`
|
||||
Unit of measurement: `V`, `mV`
|
||||
"""
|
||||
|
||||
VOLUME = "volume"
|
||||
|
|
|
@ -88,6 +88,7 @@ from homeassistant.util.unit_conversion import (
|
|||
BaseUnitConverter,
|
||||
DataRateConverter,
|
||||
DistanceConverter,
|
||||
ElectricPotentialConverter,
|
||||
InformationConverter,
|
||||
MassConverter,
|
||||
PressureConverter,
|
||||
|
@ -390,7 +391,7 @@ class SensorDeviceClass(StrEnum):
|
|||
VOLTAGE = "voltage"
|
||||
"""Voltage.
|
||||
|
||||
Unit of measurement: `V`
|
||||
Unit of measurement: `V`, `mV`
|
||||
"""
|
||||
|
||||
VOLUME = "volume"
|
||||
|
@ -476,6 +477,7 @@ UNIT_CONVERTERS: dict[SensorDeviceClass | str | None, type[BaseUnitConverter]] =
|
|||
SensorDeviceClass.PRESSURE: PressureConverter,
|
||||
SensorDeviceClass.SPEED: SpeedConverter,
|
||||
SensorDeviceClass.TEMPERATURE: TemperatureConverter,
|
||||
SensorDeviceClass.VOLTAGE: ElectricPotentialConverter,
|
||||
SensorDeviceClass.VOLUME: VolumeConverter,
|
||||
SensorDeviceClass.WATER: VolumeConverter,
|
||||
SensorDeviceClass.WEIGHT: MassConverter,
|
||||
|
@ -537,7 +539,7 @@ DEVICE_CLASS_UNITS: dict[SensorDeviceClass, set[type[StrEnum] | str | None]] = {
|
|||
SensorDeviceClass.VOLATILE_ORGANIC_COMPOUNDS: {
|
||||
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
|
||||
},
|
||||
SensorDeviceClass.VOLTAGE: {UnitOfElectricPotential.VOLT},
|
||||
SensorDeviceClass.VOLTAGE: set(UnitOfElectricPotential),
|
||||
SensorDeviceClass.VOLUME: set(UnitOfVolume),
|
||||
SensorDeviceClass.WATER: {
|
||||
UnitOfVolume.CENTUM_CUBIC_FEET,
|
||||
|
|
|
@ -4,6 +4,7 @@ from __future__ import annotations
|
|||
from homeassistant.const import (
|
||||
UNIT_NOT_RECOGNIZED_TEMPLATE,
|
||||
UnitOfDataRate,
|
||||
UnitOfElectricPotential,
|
||||
UnitOfEnergy,
|
||||
UnitOfInformation,
|
||||
UnitOfLength,
|
||||
|
@ -137,6 +138,21 @@ class DistanceConverter(BaseUnitConverter):
|
|||
}
|
||||
|
||||
|
||||
class ElectricPotentialConverter(BaseUnitConverter):
|
||||
"""Utility to convert electric potential values."""
|
||||
|
||||
UNIT_CLASS = "voltage"
|
||||
NORMALIZED_UNIT = UnitOfElectricPotential.VOLT
|
||||
_UNIT_CONVERSION: dict[str, float] = {
|
||||
UnitOfElectricPotential.VOLT: 1,
|
||||
UnitOfElectricPotential.MILLIVOLT: 1e3,
|
||||
}
|
||||
VALID_UNITS = {
|
||||
UnitOfElectricPotential.VOLT,
|
||||
UnitOfElectricPotential.MILLIVOLT,
|
||||
}
|
||||
|
||||
|
||||
class EnergyConverter(BaseUnitConverter):
|
||||
"""Utility to convert energy values."""
|
||||
|
||||
|
|
Loading…
Reference in New Issue