Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored deprecated UNITS #97368

Merged
merged 6 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Make sure that an Arlo Baby can be setup."""
from homeassistant.components.sensor import SensorStateClass
from homeassistant.const import PERCENTAGE, TEMP_CELSIUS, EntityCategory
from homeassistant.const import PERCENTAGE, EntityCategory, UnitOfTemperature
from homeassistant.core import HomeAssistant

from ..common import (
Expand Down Expand Up @@ -64,7 +64,7 @@ async def test_arlo_baby_setup(hass: HomeAssistant) -> None:
unique_id="00:00:00:00:00:00_1_1000",
friendly_name="ArloBabyA0 Temperature",
capabilities={"state_class": SensorStateClass.MEASUREMENT},
unit_of_measurement=TEMP_CELSIUS,
unit_of_measurement=UnitOfTemperature.CELSIUS,
state="24.0",
),
EntityTestInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)
from homeassistant.components.sensor import SensorStateClass
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import TEMP_CELSIUS
from homeassistant.const import UnitOfTemperature
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er

Expand Down Expand Up @@ -126,7 +126,7 @@ async def test_ecobee3_setup(hass: HomeAssistant) -> None:
friendly_name="HomeW Current Temperature",
unique_id="00:00:00:00:00:00_1_16_19",
capabilities={"state_class": SensorStateClass.MEASUREMENT},
unit_of_measurement=TEMP_CELSIUS,
unit_of_measurement=UnitOfTemperature.CELSIUS,
state="21.8",
),
EntityTestInfo(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
"""Make sure that Eve Degree (via Eve Extend) is enumerated properly."""
from homeassistant.components.number import NumberMode
from homeassistant.components.sensor import SensorStateClass
from homeassistant.const import PERCENTAGE, TEMP_CELSIUS, EntityCategory, UnitOfPressure
from homeassistant.const import (
PERCENTAGE,
EntityCategory,
UnitOfPressure,
UnitOfTemperature,
)
from homeassistant.core import HomeAssistant

from ..common import (
Expand Down Expand Up @@ -36,7 +41,7 @@ async def test_eve_degree_setup(hass: HomeAssistant) -> None:
unique_id="00:00:00:00:00:00_1_22",
friendly_name="Eve Degree AA11 Temperature",
capabilities={"state_class": SensorStateClass.MEASUREMENT},
unit_of_measurement=TEMP_CELSIUS,
unit_of_measurement=UnitOfTemperature.CELSIUS,
state="22.7719116210938",
),
EntityTestInfo(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Make sure that Mysa Living is enumerated properly."""
from homeassistant.components.climate import ClimateEntityFeature
from homeassistant.components.sensor import SensorStateClass
from homeassistant.const import PERCENTAGE, TEMP_CELSIUS
from homeassistant.const import PERCENTAGE, UnitOfTemperature
from homeassistant.core import HomeAssistant

from ..common import (
Expand Down Expand Up @@ -55,7 +55,7 @@ async def test_mysa_living_setup(hass: HomeAssistant) -> None:
entity_id="sensor.mysa_85dda9_current_temperature",
friendly_name="Mysa-85dda9 Current Temperature",
unique_id="00:00:00:00:00:00_1_20_25",
unit_of_measurement=TEMP_CELSIUS,
unit_of_measurement=UnitOfTemperature.CELSIUS,
capabilities={"state_class": SensorStateClass.MEASUREMENT},
state="24.1",
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from homeassistant.const import (
CONCENTRATION_PARTS_PER_MILLION,
PERCENTAGE,
TEMP_CELSIUS,
UnitOfTemperature,
)
from homeassistant.core import HomeAssistant

Expand Down Expand Up @@ -73,7 +73,7 @@ async def test_velux_cover_setup(hass: HomeAssistant) -> None:
friendly_name="VELUX Sensor Temperature sensor",
capabilities={"state_class": SensorStateClass.MEASUREMENT},
unique_id="00:00:00:00:00:00_2_8",
unit_of_measurement=TEMP_CELSIUS,
unit_of_measurement=UnitOfTemperature.CELSIUS,
state="18.9",
),
EntityTestInfo(
Expand Down
11 changes: 5 additions & 6 deletions tests/helpers/test_temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
PRECISION_HALVES,
PRECISION_TENTHS,
PRECISION_WHOLE,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
UnitOfTemperature,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.temperature import display_temp
Expand All @@ -18,21 +17,21 @@ def test_temperature_not_a_number(hass: HomeAssistant) -> None:
"""Test that temperature is a number."""
temp = "Temperature"
with pytest.raises(Exception) as exception:
display_temp(hass, temp, TEMP_CELSIUS, PRECISION_HALVES)
display_temp(hass, temp, UnitOfTemperature.CELSIUS, PRECISION_HALVES)

assert f"Temperature is not a number: {temp}" in str(exception.value)


def test_celsius_halves(hass: HomeAssistant) -> None:
"""Test temperature to celsius rounding to halves."""
assert display_temp(hass, TEMP, TEMP_CELSIUS, PRECISION_HALVES) == 24.5
assert display_temp(hass, TEMP, UnitOfTemperature.CELSIUS, PRECISION_HALVES) == 24.5


def test_celsius_tenths(hass: HomeAssistant) -> None:
"""Test temperature to celsius rounding to tenths."""
assert display_temp(hass, TEMP, TEMP_CELSIUS, PRECISION_TENTHS) == 24.6
assert display_temp(hass, TEMP, UnitOfTemperature.CELSIUS, PRECISION_TENTHS) == 24.6


def test_fahrenheit_wholes(hass: HomeAssistant) -> None:
"""Test temperature to fahrenheit rounding to wholes."""
assert display_temp(hass, TEMP, TEMP_FAHRENHEIT, PRECISION_WHOLE) == -4
assert display_temp(hass, TEMP, UnitOfTemperature.FAHRENHEIT, PRECISION_WHOLE) == -4
16 changes: 8 additions & 8 deletions tests/helpers/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
from homeassistant.config import async_process_ha_core_config
from homeassistant.const import (
ATTR_UNIT_OF_MEASUREMENT,
LENGTH_METERS,
LENGTH_MILLIMETERS,
MASS_GRAMS,
STATE_ON,
STATE_UNAVAILABLE,
TEMP_CELSIUS,
VOLUME_LITERS,
UnitOfLength,
UnitOfMass,
UnitOfPrecipitationDepth,
UnitOfPressure,
UnitOfSpeed,
UnitOfTemperature,
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import TemplateError
Expand All @@ -52,12 +52,12 @@ def _set_up_units(hass: HomeAssistant) -> None:
"""Set up the tests."""
hass.config.units = UnitSystem(
"custom",
accumulated_precipitation=LENGTH_MILLIMETERS,
accumulated_precipitation=UnitOfPrecipitationDepth.MILLIMETERS,
conversions={},
length=LENGTH_METERS,
mass=MASS_GRAMS,
length=UnitOfLength.METERS,
mass=UnitOfMass.GRAMS,
pressure=UnitOfPressure.PA,
temperature=TEMP_CELSIUS,
temperature=UnitOfTemperature.CELSIUS,
volume=VOLUME_LITERS,
wind_speed=UnitOfSpeed.KILOMETERS_PER_HOUR,
)
Expand Down