Update unit system unit conversions (#87632)

* Update unit system unit conversions

* Tweak tests
This commit is contained in:
Erik Montnemery
2023-02-08 10:52:54 +01:00
committed by GitHub
parent c3e733c0aa
commit 45ac8c515e
2 changed files with 282 additions and 0 deletions

View File

@ -22,6 +22,7 @@ from homeassistant.const import (
UnitOfSpeed,
UnitOfTemperature,
UnitOfVolume,
UnitOfVolumetricFlux,
)
from .unit_conversion import (
@ -244,12 +245,29 @@ METRIC_SYSTEM = UnitSystem(
("gas", UnitOfVolume.CUBIC_FEET): UnitOfVolume.CUBIC_METERS,
# Convert non-metric precipitation
("precipitation", UnitOfLength.INCHES): UnitOfLength.MILLIMETERS,
# Convert non-metric precipitation intensity
(
"precipitation_intensity",
UnitOfVolumetricFlux.INCHES_PER_DAY,
): UnitOfVolumetricFlux.MILLIMETERS_PER_DAY,
(
"precipitation_intensity",
UnitOfVolumetricFlux.INCHES_PER_HOUR,
): UnitOfVolumetricFlux.MILLIMETERS_PER_HOUR,
# Convert non-metric pressure
("pressure", UnitOfPressure.PSI): UnitOfPressure.KPA,
("pressure", UnitOfPressure.INHG): UnitOfPressure.HPA,
# Convert non-metric speeds except knots to km/h
("speed", UnitOfSpeed.FEET_PER_SECOND): UnitOfSpeed.KILOMETERS_PER_HOUR,
("speed", UnitOfSpeed.MILES_PER_HOUR): UnitOfSpeed.KILOMETERS_PER_HOUR,
(
"speed",
UnitOfVolumetricFlux.INCHES_PER_DAY,
): UnitOfVolumetricFlux.MILLIMETERS_PER_DAY,
(
"speed",
UnitOfVolumetricFlux.INCHES_PER_HOUR,
): UnitOfVolumetricFlux.MILLIMETERS_PER_HOUR,
# Convert non-metric volumes
("volume", UnitOfVolume.CENTUM_CUBIC_FEET): UnitOfVolume.CUBIC_METERS,
("volume", UnitOfVolume.CUBIC_FEET): UnitOfVolume.CUBIC_METERS,
@ -288,6 +306,15 @@ US_CUSTOMARY_SYSTEM = UnitSystem(
# Convert non-USCS precipitation
("precipitation", UnitOfLength.CENTIMETERS): UnitOfLength.INCHES,
("precipitation", UnitOfLength.MILLIMETERS): UnitOfLength.INCHES,
# Convert non-USCS precipitation intensity
(
"precipitation_intensity",
UnitOfVolumetricFlux.MILLIMETERS_PER_DAY,
): UnitOfVolumetricFlux.INCHES_PER_DAY,
(
"precipitation_intensity",
UnitOfVolumetricFlux.MILLIMETERS_PER_HOUR,
): UnitOfVolumetricFlux.INCHES_PER_HOUR,
# Convert non-USCS pressure
("pressure", UnitOfPressure.MBAR): UnitOfPressure.PSI,
("pressure", UnitOfPressure.CBAR): UnitOfPressure.PSI,
@ -299,6 +326,14 @@ US_CUSTOMARY_SYSTEM = UnitSystem(
# Convert non-USCS speeds, except knots, to mph
("speed", UnitOfSpeed.METERS_PER_SECOND): UnitOfSpeed.MILES_PER_HOUR,
("speed", UnitOfSpeed.KILOMETERS_PER_HOUR): UnitOfSpeed.MILES_PER_HOUR,
(
"speed",
UnitOfVolumetricFlux.MILLIMETERS_PER_DAY,
): UnitOfVolumetricFlux.INCHES_PER_DAY,
(
"speed",
UnitOfVolumetricFlux.MILLIMETERS_PER_HOUR,
): UnitOfVolumetricFlux.INCHES_PER_HOUR,
# Convert non-USCS volumes
("volume", UnitOfVolume.CUBIC_METERS): UnitOfVolume.CUBIC_FEET,
("volume", UnitOfVolume.LITERS): UnitOfVolume.GALLONS,