2019-03-24 17:37:31 +00:00
|
|
|
"""Pressure util functions."""
|
2021-07-18 12:43:47 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2022-09-22 14:44:09 +00:00
|
|
|
from homeassistant.const import ( # pylint: disable=unused-import # noqa: F401
|
2019-12-09 15:42:10 +00:00
|
|
|
PRESSURE,
|
2021-08-12 05:30:35 +00:00
|
|
|
PRESSURE_BAR,
|
2021-11-10 08:44:05 +00:00
|
|
|
PRESSURE_CBAR,
|
2019-03-24 17:37:31 +00:00
|
|
|
PRESSURE_HPA,
|
|
|
|
PRESSURE_INHG,
|
2021-10-01 15:08:04 +00:00
|
|
|
PRESSURE_KPA,
|
2019-12-09 15:42:10 +00:00
|
|
|
PRESSURE_MBAR,
|
2022-01-24 21:57:56 +00:00
|
|
|
PRESSURE_MMHG,
|
2019-12-09 15:42:10 +00:00
|
|
|
PRESSURE_PA,
|
2019-03-24 17:37:31 +00:00
|
|
|
PRESSURE_PSI,
|
|
|
|
UNIT_NOT_RECOGNIZED_TEMPLATE,
|
|
|
|
)
|
2022-09-28 17:39:44 +00:00
|
|
|
from homeassistant.helpers.frame import report
|
2019-03-24 17:37:31 +00:00
|
|
|
|
2022-09-22 14:44:09 +00:00
|
|
|
from .unit_conversion import PressureConverter
|
2019-03-24 17:37:31 +00:00
|
|
|
|
2022-09-28 11:49:46 +00:00
|
|
|
# pylint: disable-next=protected-access
|
|
|
|
UNIT_CONVERSION: dict[str, float] = PressureConverter._UNIT_CONVERSION
|
2022-09-27 06:16:03 +00:00
|
|
|
VALID_UNITS = PressureConverter.VALID_UNITS
|
2022-09-22 06:50:08 +00:00
|
|
|
|
2019-03-24 17:37:31 +00:00
|
|
|
|
2022-09-22 05:18:00 +00:00
|
|
|
def convert(value: float, from_unit: str, to_unit: str) -> float:
|
2019-03-24 17:37:31 +00:00
|
|
|
"""Convert one unit of measurement to another."""
|
2022-09-28 17:39:44 +00:00
|
|
|
report(
|
|
|
|
"uses pressure 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.PressureConverter instead",
|
|
|
|
error_if_core=False,
|
|
|
|
)
|
2022-09-22 14:44:09 +00:00
|
|
|
return PressureConverter.convert(value, from_unit, to_unit)
|