mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Remove deprecated pressure conversion functions (#101347)
Remove deprecated pressure conversion utils
This commit is contained in:
parent
adf6d34d95
commit
efca5ba554
@ -102,14 +102,6 @@ homeassistant.util.pil
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
homeassistant.util.pressure
|
||||
---------------------------
|
||||
|
||||
.. automodule:: homeassistant.util.pressure
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
homeassistant.util.ssl
|
||||
----------------------
|
||||
|
||||
|
@ -1,37 +0,0 @@
|
||||
"""Pressure util functions."""
|
||||
from __future__ import annotations
|
||||
|
||||
# pylint: disable-next=hass-deprecated-import
|
||||
from homeassistant.const import ( # noqa: F401
|
||||
PRESSURE,
|
||||
PRESSURE_BAR,
|
||||
PRESSURE_CBAR,
|
||||
PRESSURE_HPA,
|
||||
PRESSURE_INHG,
|
||||
PRESSURE_KPA,
|
||||
PRESSURE_MBAR,
|
||||
PRESSURE_MMHG,
|
||||
PRESSURE_PA,
|
||||
PRESSURE_PSI,
|
||||
UNIT_NOT_RECOGNIZED_TEMPLATE,
|
||||
)
|
||||
from homeassistant.helpers.frame import report
|
||||
|
||||
from .unit_conversion import PressureConverter
|
||||
|
||||
# pylint: disable-next=protected-access
|
||||
UNIT_CONVERSION: dict[str | None, float] = PressureConverter._UNIT_CONVERSION
|
||||
VALID_UNITS = PressureConverter.VALID_UNITS
|
||||
|
||||
|
||||
def convert(value: float, from_unit: str, to_unit: str) -> float:
|
||||
"""Convert one unit of measurement to another."""
|
||||
report(
|
||||
(
|
||||
"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"
|
||||
),
|
||||
error_if_core=False,
|
||||
)
|
||||
return PressureConverter.convert(value, from_unit, to_unit)
|
@ -1,139 +0,0 @@
|
||||
"""Test Home Assistant pressure utility functions."""
|
||||
import pytest
|
||||
|
||||
from homeassistant.const import UnitOfPressure
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
import homeassistant.util.pressure as pressure_util
|
||||
|
||||
INVALID_SYMBOL = "bob"
|
||||
VALID_SYMBOL = UnitOfPressure.PA
|
||||
|
||||
|
||||
def test_raise_deprecation_warning(caplog: pytest.LogCaptureFixture) -> None:
|
||||
"""Ensure that a warning is raised on use of convert."""
|
||||
assert pressure_util.convert(2, UnitOfPressure.PA, UnitOfPressure.PA) == 2
|
||||
assert "use unit_conversion.PressureConverter instead" in caplog.text
|
||||
|
||||
|
||||
def test_convert_same_unit() -> None:
|
||||
"""Test conversion from any unit to same unit."""
|
||||
assert pressure_util.convert(2, UnitOfPressure.PA, UnitOfPressure.PA) == 2
|
||||
assert pressure_util.convert(3, UnitOfPressure.HPA, UnitOfPressure.HPA) == 3
|
||||
assert pressure_util.convert(4, UnitOfPressure.MBAR, UnitOfPressure.MBAR) == 4
|
||||
assert pressure_util.convert(5, UnitOfPressure.INHG, UnitOfPressure.INHG) == 5
|
||||
assert pressure_util.convert(6, UnitOfPressure.KPA, UnitOfPressure.KPA) == 6
|
||||
assert pressure_util.convert(7, UnitOfPressure.CBAR, UnitOfPressure.CBAR) == 7
|
||||
assert pressure_util.convert(8, UnitOfPressure.MMHG, UnitOfPressure.MMHG) == 8
|
||||
|
||||
|
||||
def test_convert_invalid_unit() -> None:
|
||||
"""Test exception is thrown for invalid units."""
|
||||
with pytest.raises(HomeAssistantError, match="is not a recognized .* unit"):
|
||||
pressure_util.convert(5, INVALID_SYMBOL, VALID_SYMBOL)
|
||||
|
||||
with pytest.raises(HomeAssistantError, match="is not a recognized .* unit"):
|
||||
pressure_util.convert(5, VALID_SYMBOL, INVALID_SYMBOL)
|
||||
|
||||
|
||||
def test_convert_nonnumeric_value() -> None:
|
||||
"""Test exception is thrown for nonnumeric type."""
|
||||
with pytest.raises(TypeError):
|
||||
pressure_util.convert("a", UnitOfPressure.HPA, UnitOfPressure.INHG)
|
||||
|
||||
|
||||
def test_convert_from_hpascals() -> None:
|
||||
"""Test conversion from hPA to other units."""
|
||||
hpascals = 1000
|
||||
assert pressure_util.convert(
|
||||
hpascals, UnitOfPressure.HPA, UnitOfPressure.PSI
|
||||
) == pytest.approx(14.5037743897)
|
||||
assert pressure_util.convert(
|
||||
hpascals, UnitOfPressure.HPA, UnitOfPressure.INHG
|
||||
) == pytest.approx(29.5299801647)
|
||||
assert pressure_util.convert(
|
||||
hpascals, UnitOfPressure.HPA, UnitOfPressure.PA
|
||||
) == pytest.approx(100000)
|
||||
assert pressure_util.convert(
|
||||
hpascals, UnitOfPressure.HPA, UnitOfPressure.KPA
|
||||
) == pytest.approx(100)
|
||||
assert pressure_util.convert(
|
||||
hpascals, UnitOfPressure.HPA, UnitOfPressure.MBAR
|
||||
) == pytest.approx(1000)
|
||||
assert pressure_util.convert(
|
||||
hpascals, UnitOfPressure.HPA, UnitOfPressure.CBAR
|
||||
) == pytest.approx(100)
|
||||
|
||||
|
||||
def test_convert_from_kpascals() -> None:
|
||||
"""Test conversion from hPA to other units."""
|
||||
kpascals = 100
|
||||
assert pressure_util.convert(
|
||||
kpascals, UnitOfPressure.KPA, UnitOfPressure.PSI
|
||||
) == pytest.approx(14.5037743897)
|
||||
assert pressure_util.convert(
|
||||
kpascals, UnitOfPressure.KPA, UnitOfPressure.INHG
|
||||
) == pytest.approx(29.5299801647)
|
||||
assert pressure_util.convert(
|
||||
kpascals, UnitOfPressure.KPA, UnitOfPressure.PA
|
||||
) == pytest.approx(100000)
|
||||
assert pressure_util.convert(
|
||||
kpascals, UnitOfPressure.KPA, UnitOfPressure.HPA
|
||||
) == pytest.approx(1000)
|
||||
assert pressure_util.convert(
|
||||
kpascals, UnitOfPressure.KPA, UnitOfPressure.MBAR
|
||||
) == pytest.approx(1000)
|
||||
assert pressure_util.convert(
|
||||
kpascals, UnitOfPressure.KPA, UnitOfPressure.CBAR
|
||||
) == pytest.approx(100)
|
||||
|
||||
|
||||
def test_convert_from_inhg() -> None:
|
||||
"""Test conversion from inHg to other units."""
|
||||
inhg = 30
|
||||
assert pressure_util.convert(
|
||||
inhg, UnitOfPressure.INHG, UnitOfPressure.PSI
|
||||
) == pytest.approx(14.7346266155)
|
||||
assert pressure_util.convert(
|
||||
inhg, UnitOfPressure.INHG, UnitOfPressure.KPA
|
||||
) == pytest.approx(101.59167)
|
||||
assert pressure_util.convert(
|
||||
inhg, UnitOfPressure.INHG, UnitOfPressure.HPA
|
||||
) == pytest.approx(1015.9167)
|
||||
assert pressure_util.convert(
|
||||
inhg, UnitOfPressure.INHG, UnitOfPressure.PA
|
||||
) == pytest.approx(101591.67)
|
||||
assert pressure_util.convert(
|
||||
inhg, UnitOfPressure.INHG, UnitOfPressure.MBAR
|
||||
) == pytest.approx(1015.9167)
|
||||
assert pressure_util.convert(
|
||||
inhg, UnitOfPressure.INHG, UnitOfPressure.CBAR
|
||||
) == pytest.approx(101.59167)
|
||||
assert pressure_util.convert(
|
||||
inhg, UnitOfPressure.INHG, UnitOfPressure.MMHG
|
||||
) == pytest.approx(762)
|
||||
|
||||
|
||||
def test_convert_from_mmhg() -> None:
|
||||
"""Test conversion from mmHg to other units."""
|
||||
inhg = 30
|
||||
assert pressure_util.convert(
|
||||
inhg, UnitOfPressure.MMHG, UnitOfPressure.PSI
|
||||
) == pytest.approx(0.580103)
|
||||
assert pressure_util.convert(
|
||||
inhg, UnitOfPressure.MMHG, UnitOfPressure.KPA
|
||||
) == pytest.approx(3.99967)
|
||||
assert pressure_util.convert(
|
||||
inhg, UnitOfPressure.MMHG, UnitOfPressure.HPA
|
||||
) == pytest.approx(39.9967)
|
||||
assert pressure_util.convert(
|
||||
inhg, UnitOfPressure.MMHG, UnitOfPressure.PA
|
||||
) == pytest.approx(3999.67)
|
||||
assert pressure_util.convert(
|
||||
inhg, UnitOfPressure.MMHG, UnitOfPressure.MBAR
|
||||
) == pytest.approx(39.9967)
|
||||
assert pressure_util.convert(
|
||||
inhg, UnitOfPressure.MMHG, UnitOfPressure.CBAR
|
||||
) == pytest.approx(3.99967)
|
||||
assert pressure_util.convert(
|
||||
inhg, UnitOfPressure.MMHG, UnitOfPressure.INHG
|
||||
) == pytest.approx(1.181102)
|
Loading…
x
Reference in New Issue
Block a user