mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Migrates tests to use UnitOfPressure enum (#86785)
This commit is contained in:
parent
561fc2d771
commit
89c0b27b42
@ -2,7 +2,7 @@
|
||||
|
||||
from homeassistant.components.number import NumberMode
|
||||
from homeassistant.components.sensor import SensorStateClass
|
||||
from homeassistant.const import PERCENTAGE, PRESSURE_HPA, TEMP_CELSIUS
|
||||
from homeassistant.const import PERCENTAGE, TEMP_CELSIUS, UnitOfPressure
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
|
||||
from ..common import (
|
||||
@ -52,7 +52,7 @@ async def test_eve_degree_setup(hass):
|
||||
entity_id="sensor.eve_degree_aa11_air_pressure",
|
||||
unique_id="00:00:00:00:00:00_1_30_32",
|
||||
friendly_name="Eve Degree AA11 Air Pressure",
|
||||
unit_of_measurement=PRESSURE_HPA,
|
||||
unit_of_measurement=UnitOfPressure.HPA,
|
||||
capabilities={"state_class": SensorStateClass.MEASUREMENT},
|
||||
state="1005.70001220703",
|
||||
),
|
||||
|
@ -20,10 +20,10 @@ from homeassistant.const import (
|
||||
LENGTH_METERS,
|
||||
LENGTH_MILLIMETERS,
|
||||
MASS_GRAMS,
|
||||
PRESSURE_PA,
|
||||
STATE_ON,
|
||||
TEMP_CELSIUS,
|
||||
VOLUME_LITERS,
|
||||
UnitOfPressure,
|
||||
UnitOfSpeed,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
@ -52,7 +52,7 @@ def _set_up_units(hass: HomeAssistant) -> None:
|
||||
conversions={},
|
||||
length=LENGTH_METERS,
|
||||
mass=MASS_GRAMS,
|
||||
pressure=PRESSURE_PA,
|
||||
pressure=UnitOfPressure.PA,
|
||||
temperature=TEMP_CELSIUS,
|
||||
volume=VOLUME_LITERS,
|
||||
wind_speed=UnitOfSpeed.KILOMETERS_PER_HOUR,
|
||||
|
@ -17,9 +17,9 @@ from homeassistant.const import (
|
||||
PERCENTAGE,
|
||||
POWER_VOLT_AMPERE,
|
||||
POWER_VOLT_AMPERE_REACTIVE,
|
||||
PRESSURE_HPA,
|
||||
SIGNAL_STRENGTH_DECIBELS,
|
||||
VOLUME_CUBIC_METERS,
|
||||
UnitOfPressure,
|
||||
)
|
||||
|
||||
from tests.common import MockEntity
|
||||
@ -44,7 +44,7 @@ UNITS_OF_MEASUREMENT = {
|
||||
SensorDeviceClass.SIGNAL_STRENGTH: SIGNAL_STRENGTH_DECIBELS, # signal strength (dB/dBm)
|
||||
SensorDeviceClass.SULPHUR_DIOXIDE: CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, # µg/m³ of sulphur dioxide
|
||||
SensorDeviceClass.TEMPERATURE: "C", # temperature (C/F)
|
||||
SensorDeviceClass.PRESSURE: PRESSURE_HPA, # pressure (hPa/mbar)
|
||||
SensorDeviceClass.PRESSURE: UnitOfPressure.HPA, # pressure (hPa/mbar)
|
||||
SensorDeviceClass.POWER: "kW", # power (W/kW)
|
||||
SensorDeviceClass.CURRENT: "A", # current (A)
|
||||
SensorDeviceClass.ENERGY: "kWh", # energy (Wh/kWh/MWh)
|
||||
|
@ -1,38 +1,29 @@
|
||||
"""Test Home Assistant pressure utility functions."""
|
||||
import pytest
|
||||
|
||||
from homeassistant.const import (
|
||||
PRESSURE_CBAR,
|
||||
PRESSURE_HPA,
|
||||
PRESSURE_INHG,
|
||||
PRESSURE_KPA,
|
||||
PRESSURE_MBAR,
|
||||
PRESSURE_MMHG,
|
||||
PRESSURE_PA,
|
||||
PRESSURE_PSI,
|
||||
)
|
||||
from homeassistant.const import UnitOfPressure
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
import homeassistant.util.pressure as pressure_util
|
||||
|
||||
INVALID_SYMBOL = "bob"
|
||||
VALID_SYMBOL = PRESSURE_PA
|
||||
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, PRESSURE_PA, PRESSURE_PA) == 2
|
||||
assert pressure_util.convert(2, UnitOfPressure.PA, UnitOfPressure.PA) == 2
|
||||
assert "use unit_conversion.PressureConverter instead" in caplog.text
|
||||
|
||||
|
||||
def test_convert_same_unit():
|
||||
"""Test conversion from any unit to same unit."""
|
||||
assert pressure_util.convert(2, PRESSURE_PA, PRESSURE_PA) == 2
|
||||
assert pressure_util.convert(3, PRESSURE_HPA, PRESSURE_HPA) == 3
|
||||
assert pressure_util.convert(4, PRESSURE_MBAR, PRESSURE_MBAR) == 4
|
||||
assert pressure_util.convert(5, PRESSURE_INHG, PRESSURE_INHG) == 5
|
||||
assert pressure_util.convert(6, PRESSURE_KPA, PRESSURE_KPA) == 6
|
||||
assert pressure_util.convert(7, PRESSURE_CBAR, PRESSURE_CBAR) == 7
|
||||
assert pressure_util.convert(8, PRESSURE_MMHG, PRESSURE_MMHG) == 8
|
||||
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():
|
||||
@ -47,102 +38,102 @@ def test_convert_invalid_unit():
|
||||
def test_convert_nonnumeric_value():
|
||||
"""Test exception is thrown for nonnumeric type."""
|
||||
with pytest.raises(TypeError):
|
||||
pressure_util.convert("a", PRESSURE_HPA, PRESSURE_INHG)
|
||||
pressure_util.convert("a", UnitOfPressure.HPA, UnitOfPressure.INHG)
|
||||
|
||||
|
||||
def test_convert_from_hpascals():
|
||||
"""Test conversion from hPA to other units."""
|
||||
hpascals = 1000
|
||||
assert pressure_util.convert(hpascals, PRESSURE_HPA, PRESSURE_PSI) == pytest.approx(
|
||||
14.5037743897
|
||||
)
|
||||
assert pressure_util.convert(
|
||||
hpascals, PRESSURE_HPA, PRESSURE_INHG
|
||||
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, PRESSURE_HPA, PRESSURE_PA) == pytest.approx(
|
||||
100000
|
||||
)
|
||||
assert pressure_util.convert(hpascals, PRESSURE_HPA, PRESSURE_KPA) == pytest.approx(
|
||||
100
|
||||
)
|
||||
assert pressure_util.convert(
|
||||
hpascals, PRESSURE_HPA, PRESSURE_MBAR
|
||||
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, PRESSURE_HPA, PRESSURE_CBAR
|
||||
hpascals, UnitOfPressure.HPA, UnitOfPressure.CBAR
|
||||
) == pytest.approx(100)
|
||||
|
||||
|
||||
def test_convert_from_kpascals():
|
||||
"""Test conversion from hPA to other units."""
|
||||
kpascals = 100
|
||||
assert pressure_util.convert(kpascals, PRESSURE_KPA, PRESSURE_PSI) == pytest.approx(
|
||||
14.5037743897
|
||||
)
|
||||
assert pressure_util.convert(
|
||||
kpascals, PRESSURE_KPA, PRESSURE_INHG
|
||||
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, PRESSURE_KPA, PRESSURE_PA) == pytest.approx(
|
||||
100000
|
||||
)
|
||||
assert pressure_util.convert(kpascals, PRESSURE_KPA, PRESSURE_HPA) == pytest.approx(
|
||||
1000
|
||||
)
|
||||
assert pressure_util.convert(
|
||||
kpascals, PRESSURE_KPA, PRESSURE_MBAR
|
||||
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, PRESSURE_KPA, PRESSURE_CBAR
|
||||
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():
|
||||
"""Test conversion from inHg to other units."""
|
||||
inhg = 30
|
||||
assert pressure_util.convert(inhg, PRESSURE_INHG, PRESSURE_PSI) == pytest.approx(
|
||||
14.7346266155
|
||||
)
|
||||
assert pressure_util.convert(inhg, PRESSURE_INHG, PRESSURE_KPA) == pytest.approx(
|
||||
101.59167
|
||||
)
|
||||
assert pressure_util.convert(inhg, PRESSURE_INHG, PRESSURE_HPA) == pytest.approx(
|
||||
1015.9167
|
||||
)
|
||||
assert pressure_util.convert(inhg, PRESSURE_INHG, PRESSURE_PA) == pytest.approx(
|
||||
101591.67
|
||||
)
|
||||
assert pressure_util.convert(inhg, PRESSURE_INHG, PRESSURE_MBAR) == pytest.approx(
|
||||
1015.9167
|
||||
)
|
||||
assert pressure_util.convert(inhg, PRESSURE_INHG, PRESSURE_CBAR) == pytest.approx(
|
||||
101.59167
|
||||
)
|
||||
assert pressure_util.convert(inhg, PRESSURE_INHG, PRESSURE_MMHG) == pytest.approx(
|
||||
762
|
||||
)
|
||||
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():
|
||||
"""Test conversion from mmHg to other units."""
|
||||
inhg = 30
|
||||
assert pressure_util.convert(inhg, PRESSURE_MMHG, PRESSURE_PSI) == pytest.approx(
|
||||
0.580103
|
||||
)
|
||||
assert pressure_util.convert(inhg, PRESSURE_MMHG, PRESSURE_KPA) == pytest.approx(
|
||||
3.99967
|
||||
)
|
||||
assert pressure_util.convert(inhg, PRESSURE_MMHG, PRESSURE_HPA) == pytest.approx(
|
||||
39.9967
|
||||
)
|
||||
assert pressure_util.convert(inhg, PRESSURE_MMHG, PRESSURE_PA) == pytest.approx(
|
||||
3999.67
|
||||
)
|
||||
assert pressure_util.convert(inhg, PRESSURE_MMHG, PRESSURE_MBAR) == pytest.approx(
|
||||
39.9967
|
||||
)
|
||||
assert pressure_util.convert(inhg, PRESSURE_MMHG, PRESSURE_CBAR) == pytest.approx(
|
||||
3.99967
|
||||
)
|
||||
assert pressure_util.convert(inhg, PRESSURE_MMHG, PRESSURE_INHG) == pytest.approx(
|
||||
1.181102
|
||||
)
|
||||
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