2021-11-09 07:12:28 +00:00
|
|
|
"""Distance util functions."""
|
|
|
|
from __future__ import annotations
|
|
|
|
|
2022-09-23 12:23:59 +00:00
|
|
|
from homeassistant.const import ( # pylint: disable=unused-import # noqa: F401
|
2021-11-09 07:12:28 +00:00
|
|
|
SPEED,
|
2022-06-29 14:34:41 +00:00
|
|
|
SPEED_FEET_PER_SECOND,
|
2021-11-09 07:12:28 +00:00
|
|
|
SPEED_INCHES_PER_DAY,
|
|
|
|
SPEED_INCHES_PER_HOUR,
|
|
|
|
SPEED_KILOMETERS_PER_HOUR,
|
2022-06-29 14:34:41 +00:00
|
|
|
SPEED_KNOTS,
|
2021-11-09 07:12:28 +00:00
|
|
|
SPEED_METERS_PER_SECOND,
|
|
|
|
SPEED_MILES_PER_HOUR,
|
|
|
|
SPEED_MILLIMETERS_PER_DAY,
|
|
|
|
UNIT_NOT_RECOGNIZED_TEMPLATE,
|
|
|
|
)
|
2022-09-28 17:39:44 +00:00
|
|
|
from homeassistant.helpers.frame import report
|
2021-11-09 07:12:28 +00:00
|
|
|
|
2022-09-23 12:23:59 +00:00
|
|
|
from .unit_conversion import ( # pylint: disable=unused-import # noqa: F401
|
|
|
|
_FOOT_TO_M as FOOT_TO_M,
|
|
|
|
_HRS_TO_SECS as HRS_TO_SECS,
|
|
|
|
_IN_TO_M as IN_TO_M,
|
|
|
|
_KM_TO_M as KM_TO_M,
|
|
|
|
_MILE_TO_M as MILE_TO_M,
|
|
|
|
_NAUTICAL_MILE_TO_M as NAUTICAL_MILE_TO_M,
|
|
|
|
SpeedConverter,
|
2022-09-07 14:18:00 +00:00
|
|
|
)
|
|
|
|
|
2022-09-28 11:49:46 +00:00
|
|
|
# pylint: disable-next=protected-access
|
2022-09-30 18:38:11 +00:00
|
|
|
UNIT_CONVERSION: dict[str, float] = SpeedConverter._UNIT_CONVERSION
|
2022-09-23 12:23:59 +00:00
|
|
|
VALID_UNITS = SpeedConverter.VALID_UNITS
|
2021-11-09 07:12:28 +00:00
|
|
|
|
|
|
|
|
2022-09-23 12:23:59 +00:00
|
|
|
def convert(value: float, from_unit: str, to_unit: str) -> float:
|
2021-11-09 07:12:28 +00:00
|
|
|
"""Convert one unit of measurement to another."""
|
2022-09-28 17:39:44 +00:00
|
|
|
report(
|
|
|
|
"uses speed utility. This is deprecated since 2022.10 and will "
|
2022-10-12 22:06:23 +00:00
|
|
|
"stop working in Home Assistant 2023.4, it should be updated to use "
|
2022-09-28 17:39:44 +00:00
|
|
|
"unit_conversion.SpeedConverter instead",
|
|
|
|
error_if_core=False,
|
|
|
|
)
|
2022-09-23 12:23:59 +00:00
|
|
|
return SpeedConverter.convert(value, from_unit, to_unit)
|