mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 04:07:08 +00:00
Add mV as a unit for voltage and enable conversions (#84805)
fixes undefined
This commit is contained in:
parent
bcf32f8331
commit
b2388b74d9
@ -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…
x
Reference in New Issue
Block a user