mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add preferred wind speed unit to unit systems (#90504)
* Add preferred wind speed unit to unit systems * Tweak * Update tests
This commit is contained in:
parent
b316ffff9b
commit
ead88cc3f8
@ -277,6 +277,12 @@ METRIC_SYSTEM = UnitSystem(
|
||||
("water", UnitOfVolume.CENTUM_CUBIC_FEET): UnitOfVolume.CUBIC_METERS,
|
||||
("water", UnitOfVolume.CUBIC_FEET): UnitOfVolume.CUBIC_METERS,
|
||||
("water", UnitOfVolume.GALLONS): UnitOfVolume.LITERS,
|
||||
# Convert wind speeds except knots to km/h
|
||||
**{
|
||||
("wind_speed", unit): UnitOfSpeed.KILOMETERS_PER_HOUR
|
||||
for unit in UnitOfSpeed
|
||||
if unit not in (UnitOfSpeed.KILOMETERS_PER_HOUR, UnitOfSpeed.KNOTS)
|
||||
},
|
||||
},
|
||||
length=UnitOfLength.KILOMETERS,
|
||||
mass=UnitOfMass.GRAMS,
|
||||
@ -341,6 +347,12 @@ US_CUSTOMARY_SYSTEM = UnitSystem(
|
||||
# Convert non-USCS volumes of water meters
|
||||
("water", UnitOfVolume.CUBIC_METERS): UnitOfVolume.CUBIC_FEET,
|
||||
("water", UnitOfVolume.LITERS): UnitOfVolume.GALLONS,
|
||||
# Convert wind speeds except knots to mph
|
||||
**{
|
||||
("wind_speed", unit): UnitOfSpeed.MILES_PER_HOUR
|
||||
for unit in UnitOfSpeed
|
||||
if unit not in (UnitOfSpeed.KNOTS, UnitOfSpeed.MILES_PER_HOUR)
|
||||
},
|
||||
},
|
||||
length=UnitOfLength.MILES,
|
||||
mass=UnitOfMass.POUNDS,
|
||||
|
@ -457,6 +457,25 @@ def test_get_unit_system_invalid(key: str) -> None:
|
||||
(SensorDeviceClass.WATER, UnitOfVolume.CUBIC_METERS, None),
|
||||
(SensorDeviceClass.WATER, UnitOfVolume.LITERS, None),
|
||||
(SensorDeviceClass.WATER, "very_much", None),
|
||||
# Test wind speed conversion
|
||||
(
|
||||
SensorDeviceClass.WIND_SPEED,
|
||||
UnitOfSpeed.FEET_PER_SECOND,
|
||||
UnitOfSpeed.KILOMETERS_PER_HOUR,
|
||||
),
|
||||
(
|
||||
SensorDeviceClass.WIND_SPEED,
|
||||
UnitOfSpeed.MILES_PER_HOUR,
|
||||
UnitOfSpeed.KILOMETERS_PER_HOUR,
|
||||
),
|
||||
(SensorDeviceClass.WIND_SPEED, UnitOfSpeed.KILOMETERS_PER_HOUR, None),
|
||||
(SensorDeviceClass.WIND_SPEED, UnitOfSpeed.KNOTS, None),
|
||||
(
|
||||
SensorDeviceClass.WIND_SPEED,
|
||||
UnitOfSpeed.METERS_PER_SECOND,
|
||||
UnitOfSpeed.KILOMETERS_PER_HOUR,
|
||||
),
|
||||
(SensorDeviceClass.WIND_SPEED, "very_fast", None),
|
||||
),
|
||||
)
|
||||
def test_get_metric_converted_unit_(
|
||||
@ -657,6 +676,25 @@ def test_metric_converted_units(device_class: SensorDeviceClass) -> None:
|
||||
(SensorDeviceClass.WATER, UnitOfVolume.CUBIC_FEET, None),
|
||||
(SensorDeviceClass.WATER, UnitOfVolume.GALLONS, None),
|
||||
(SensorDeviceClass.WATER, "very_much", None),
|
||||
# Test wind speed conversion
|
||||
(
|
||||
SensorDeviceClass.WIND_SPEED,
|
||||
UnitOfSpeed.METERS_PER_SECOND,
|
||||
UnitOfSpeed.MILES_PER_HOUR,
|
||||
),
|
||||
(
|
||||
SensorDeviceClass.WIND_SPEED,
|
||||
UnitOfSpeed.KILOMETERS_PER_HOUR,
|
||||
UnitOfSpeed.MILES_PER_HOUR,
|
||||
),
|
||||
(
|
||||
SensorDeviceClass.WIND_SPEED,
|
||||
UnitOfSpeed.FEET_PER_SECOND,
|
||||
UnitOfSpeed.MILES_PER_HOUR,
|
||||
),
|
||||
(SensorDeviceClass.WIND_SPEED, UnitOfSpeed.KNOTS, None),
|
||||
(SensorDeviceClass.WIND_SPEED, UnitOfSpeed.MILES_PER_HOUR, None),
|
||||
(SensorDeviceClass.WIND_SPEED, "very_fast", None),
|
||||
),
|
||||
)
|
||||
def test_get_us_converted_unit(
|
||||
|
Loading…
x
Reference in New Issue
Block a user