Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add preferred wind speed unit to unit systems #90504

Merged
merged 3 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions homeassistant/util/unit_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,12 @@ def _deprecated_unit_system(value: str) -> str:
("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,
Expand Down Expand Up @@ -341,6 +347,12 @@ def _deprecated_unit_system(value: str) -> str:
# 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,
Expand Down
38 changes: 38 additions & 0 deletions tests/util/test_unit_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_(
Expand Down Expand Up @@ -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(
Expand Down