2019-03-24 13:37:31 -04:00
|
|
|
"""Pressure util functions."""
|
2021-07-18 14:43:47 +02:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2022-12-21 15:24:11 +01:00
|
|
|
# pylint: disable-next=unused-import,hass-deprecated-import
|
|
|
|
from homeassistant.const import ( # noqa: F401
|
2019-12-09 16:42:10 +01:00
|
|
|
PRESSURE,
|
2021-08-12 07:30:35 +02:00
|
|
|
PRESSURE_BAR,
|
2021-11-10 01:44:05 -07:00
|
|
|
PRESSURE_CBAR,
|
2019-03-24 13:37:31 -04:00
|
|
|
PRESSURE_HPA,
|
|
|
|
PRESSURE_INHG,
|
2021-10-01 11:08:04 -04:00
|
|
|
PRESSURE_KPA,
|
2019-12-09 16:42:10 +01:00
|
|
|
PRESSURE_MBAR,
|
2022-01-24 22:57:56 +01:00
|
|
|
PRESSURE_MMHG,
|
2019-12-09 16:42:10 +01:00
|
|
|
PRESSURE_PA,
|
2019-03-24 13:37:31 -04:00
|
|
|
PRESSURE_PSI,
|
|
|
|
UNIT_NOT_RECOGNIZED_TEMPLATE,
|
|
|
|
)
|
2022-09-28 19:39:44 +02:00
|
|
|
from homeassistant.helpers.frame import report
|
2019-03-24 13:37:31 -04:00
|
|
|
|
2022-09-22 16:44:09 +02:00
|
|
|
from .unit_conversion import PressureConverter
|
2019-03-24 13:37:31 -04:00
|
|
|
|
2022-09-28 13:49:46 +02:00
|
|
|
# pylint: disable-next=protected-access
|
2023-01-12 09:20:00 +01:00
|
|
|
UNIT_CONVERSION: dict[str | None, float] = PressureConverter._UNIT_CONVERSION
|
2022-09-27 07:16:03 +01:00
|
|
|
VALID_UNITS = PressureConverter.VALID_UNITS
|
2022-09-22 08:50:08 +02:00
|
|
|
|
2019-03-24 13:37:31 -04:00
|
|
|
|
2022-09-22 07:18:00 +02:00
|
|
|
def convert(value: float, from_unit: str, to_unit: str) -> float:
|
2019-03-24 13:37:31 -04:00
|
|
|
"""Convert one unit of measurement to another."""
|
2022-09-28 19:39:44 +02:00
|
|
|
report(
|
2022-12-27 11:18:56 +01:00
|
|
|
(
|
|
|
|
"uses pressure utility. This is deprecated since 2022.10 and will "
|
|
|
|
"stop working in Home Assistant 2023.4, it should be updated to use "
|
|
|
|
"unit_conversion.PressureConverter instead"
|
|
|
|
),
|
2022-09-28 19:39:44 +02:00
|
|
|
error_if_core=False,
|
|
|
|
)
|
2022-09-22 16:44:09 +02:00
|
|
|
return PressureConverter.convert(value, from_unit, to_unit)
|