Teach UnitlessRatioConverter about ppm and ppb (#92989)
parent
7807df4426
commit
9a70f47049
|
@ -466,6 +466,7 @@ UNIT_CONVERTERS: dict[SensorDeviceClass | str | None, type[BaseUnitConverter]] =
|
|||
SensorDeviceClass.PRESSURE: PressureConverter,
|
||||
SensorDeviceClass.SPEED: SpeedConverter,
|
||||
SensorDeviceClass.TEMPERATURE: TemperatureConverter,
|
||||
SensorDeviceClass.VOLATILE_ORGANIC_COMPOUNDS_PARTS: UnitlessRatioConverter,
|
||||
SensorDeviceClass.VOLTAGE: ElectricPotentialConverter,
|
||||
SensorDeviceClass.VOLUME: VolumeConverter,
|
||||
SensorDeviceClass.VOLUME_STORAGE: VolumeConverter,
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from homeassistant.const import (
|
||||
CONCENTRATION_PARTS_PER_BILLION,
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
PERCENTAGE,
|
||||
UNIT_NOT_RECOGNIZED_TEMPLATE,
|
||||
UnitOfDataRate,
|
||||
|
@ -421,6 +423,8 @@ class UnitlessRatioConverter(BaseUnitConverter):
|
|||
NORMALIZED_UNIT = None
|
||||
_UNIT_CONVERSION: dict[str | None, float] = {
|
||||
None: 1,
|
||||
CONCENTRATION_PARTS_PER_BILLION: 1000000000,
|
||||
CONCENTRATION_PARTS_PER_MILLION: 1000000,
|
||||
PERCENTAGE: 100,
|
||||
}
|
||||
VALID_UNITS = {
|
||||
|
|
|
@ -6,6 +6,8 @@ import inspect
|
|||
import pytest
|
||||
|
||||
from homeassistant.const import (
|
||||
CONCENTRATION_PARTS_PER_BILLION,
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
PERCENTAGE,
|
||||
UnitOfDataRate,
|
||||
UnitOfElectricCurrent,
|
||||
|
@ -365,6 +367,8 @@ _CONVERTED_VALUE: dict[
|
|||
],
|
||||
UnitlessRatioConverter: [
|
||||
(5, None, 500, PERCENTAGE),
|
||||
(5, None, 5000000000, CONCENTRATION_PARTS_PER_BILLION),
|
||||
(5, None, 5000000, CONCENTRATION_PARTS_PER_MILLION),
|
||||
(5, PERCENTAGE, 0.05, None),
|
||||
],
|
||||
VolumeConverter: [
|
||||
|
|
Loading…
Reference in New Issue