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 mm/s and in/s As Unit Of Speed #125044

Merged
merged 8 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
must support imperial as well
  • Loading branch information
bdraco committed Sep 8, 2024
commit d82413435a9b4908d73e0534a8b476de0a36b3fa
2 changes: 1 addition & 1 deletion homeassistant/components/sensor/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ class SensorDeviceClass(StrEnum):

Unit of measurement: `SPEED_*` units or `UnitOfVolumetricFlux`
- SI /metric: `mm/d`, `mm/h`, `m/s`, `km/h`, `mm/s`
- USCS / imperial: `in/d`, `in/h`, `ft/s`, `mph`
- USCS / imperial: `in/d`, `in/h`, `in/s`, `ft/s`, `mph`
- Nautical: `kn`
- Beaufort: `Beaufort`
"""
Expand Down
1 change: 1 addition & 0 deletions homeassistant/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,7 @@ class UnitOfSpeed(StrEnum):

BEAUFORT = "Beaufort"
FEET_PER_SECOND = "ft/s"
INCHES_PER_SECOND = "in/s"
METERS_PER_SECOND = "m/s"
KILOMETERS_PER_HOUR = "km/h"
KNOTS = "kn"
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/util/unit_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ class SpeedConverter(BaseUnitConverter):
UnitOfVolumetricFlux.MILLIMETERS_PER_DAY: _DAYS_TO_SECS / _MM_TO_M,
UnitOfVolumetricFlux.MILLIMETERS_PER_HOUR: _HRS_TO_SECS / _MM_TO_M,
UnitOfSpeed.FEET_PER_SECOND: 1 / _FOOT_TO_M,
UnitOfSpeed.INCHES_PER_SECOND: 1 / _IN_TO_M,
UnitOfSpeed.KILOMETERS_PER_HOUR: _HRS_TO_SECS / _KM_TO_M,
UnitOfSpeed.KNOTS: _HRS_TO_SECS / _NAUTICAL_MILE_TO_M,
UnitOfSpeed.METERS_PER_SECOND: 1,
Expand All @@ -345,6 +346,7 @@ class SpeedConverter(BaseUnitConverter):
UnitOfVolumetricFlux.INCHES_PER_HOUR,
UnitOfVolumetricFlux.MILLIMETERS_PER_DAY,
UnitOfVolumetricFlux.MILLIMETERS_PER_HOUR,
UnitOfSpeed.INCHES_PER_SECOND,
UnitOfSpeed.FEET_PER_SECOND,
UnitOfSpeed.KILOMETERS_PER_HOUR,
UnitOfSpeed.KNOTS,
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/util/unit_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ def _deprecated_unit_system(value: str) -> str:
("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.INCHES_PER_SECOND): UnitOfSpeed.MILLIMETERS_PER_SECOND,
("speed", UnitOfSpeed.MILES_PER_HOUR): UnitOfSpeed.KILOMETERS_PER_HOUR,
(
"speed",
Expand Down Expand Up @@ -332,6 +333,7 @@ def _deprecated_unit_system(value: str) -> str:
("pressure", UnitOfPressure.MMHG): UnitOfPressure.INHG,
# Convert non-USCS speeds, except knots, to mph
("speed", UnitOfSpeed.METERS_PER_SECOND): UnitOfSpeed.MILES_PER_HOUR,
("speed", UnitOfSpeed.MILLIMETERS_PER_SECOND): UnitOfSpeed.INCHES_PER_SECOND,
("speed", UnitOfSpeed.KILOMETERS_PER_HOUR): UnitOfSpeed.MILES_PER_HOUR,
(
"speed",
Expand Down
1 change: 1 addition & 0 deletions tests/components/sensor/test_websocket_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ async def test_device_class_units(
"ft/s",
"in/d",
"in/h",
"in/s",
"km/h",
"kn",
"m/s",
Expand Down
7 changes: 7 additions & 0 deletions tests/util/test_unit_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,13 @@
5000,
UnitOfSpeed.MILLIMETERS_PER_SECOND,
),
# 5 m/s ÷ 0.0254 = 196.8503937 in/s
(
5,
UnitOfSpeed.METERS_PER_SECOND,
5 / 0.0254,
UnitOfSpeed.INCHES_PER_SECOND,
),
# 5000 in/h / 39.3701 in/m / 3600 s/h = 0.03528 m/s
(
5000,
Expand Down
Loading