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