Teach UnitlessRatioConverter about ppm and ppb (#92989)

pull/92999/head
Erik Montnemery 2023-05-12 16:46:37 +02:00 committed by GitHub
parent 7807df4426
commit 9a70f47049
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 0 deletions

View File

@ -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,

View File

@ -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 = {

View File

@ -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: [