mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Replace deprecated unit converter utils (#85927)
This commit is contained in:
parent
d92b423127
commit
b20eb54800
@ -20,7 +20,7 @@ from homeassistant.const import (
|
|||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||||
from homeassistant.util.temperature import convert as convert_temperature
|
from homeassistant.util.unit_conversion import TemperatureConverter
|
||||||
|
|
||||||
from . import MazdaEntity
|
from . import MazdaEntity
|
||||||
from .const import DATA_CLIENT, DATA_COORDINATOR, DATA_REGION, DOMAIN
|
from .const import DATA_CLIENT, DATA_COORDINATOR, DATA_REGION, DOMAIN
|
||||||
@ -129,7 +129,7 @@ class MazdaClimateEntity(MazdaEntity, ClimateEntity):
|
|||||||
"interiorTemperatureCelsius"
|
"interiorTemperatureCelsius"
|
||||||
]
|
]
|
||||||
if self.data["hvacSetting"]["temperatureUnit"] == "F":
|
if self.data["hvacSetting"]["temperatureUnit"] == "F":
|
||||||
self._attr_current_temperature = convert_temperature(
|
self._attr_current_temperature = TemperatureConverter.convert(
|
||||||
current_temperature_celsius,
|
current_temperature_celsius,
|
||||||
UnitOfTemperature.CELSIUS,
|
UnitOfTemperature.CELSIUS,
|
||||||
UnitOfTemperature.FAHRENHEIT,
|
UnitOfTemperature.FAHRENHEIT,
|
||||||
|
@ -50,10 +50,12 @@ from homeassistant.const import (
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
from homeassistant.util.distance import convert as convert_distance
|
from homeassistant.util.unit_conversion import (
|
||||||
from homeassistant.util.pressure import convert as convert_pressure
|
DistanceConverter,
|
||||||
from homeassistant.util.speed import convert as convert_speed
|
PressureConverter,
|
||||||
from homeassistant.util.temperature import convert as convert_temperature
|
SpeedConverter,
|
||||||
|
TemperatureConverter,
|
||||||
|
)
|
||||||
from homeassistant.util.unit_system import METRIC_SYSTEM, US_CUSTOMARY_SYSTEM
|
from homeassistant.util.unit_system import METRIC_SYSTEM, US_CUSTOMARY_SYSTEM
|
||||||
|
|
||||||
from tests.testing_config.custom_components.test import weather as WeatherPlatform
|
from tests.testing_config.custom_components.test import weather as WeatherPlatform
|
||||||
@ -155,7 +157,7 @@ async def test_temperature(
|
|||||||
"""Test temperature."""
|
"""Test temperature."""
|
||||||
hass.config.units = unit_system
|
hass.config.units = unit_system
|
||||||
native_value = 38
|
native_value = 38
|
||||||
state_value = convert_temperature(native_value, native_unit, state_unit)
|
state_value = TemperatureConverter.convert(native_value, native_unit, state_unit)
|
||||||
|
|
||||||
entity0 = await create_entity(
|
entity0 = await create_entity(
|
||||||
hass, native_temperature=native_value, native_temperature_unit=native_unit
|
hass, native_temperature=native_value, native_temperature_unit=native_unit
|
||||||
@ -221,7 +223,7 @@ async def test_pressure(
|
|||||||
"""Test pressure."""
|
"""Test pressure."""
|
||||||
hass.config.units = unit_system
|
hass.config.units = unit_system
|
||||||
native_value = 30
|
native_value = 30
|
||||||
state_value = convert_pressure(native_value, native_unit, state_unit)
|
state_value = PressureConverter.convert(native_value, native_unit, state_unit)
|
||||||
|
|
||||||
entity0 = await create_entity(
|
entity0 = await create_entity(
|
||||||
hass, native_pressure=native_value, native_pressure_unit=native_unit
|
hass, native_pressure=native_value, native_pressure_unit=native_unit
|
||||||
@ -283,7 +285,7 @@ async def test_wind_speed(
|
|||||||
"""Test wind speed."""
|
"""Test wind speed."""
|
||||||
hass.config.units = unit_system
|
hass.config.units = unit_system
|
||||||
native_value = 10
|
native_value = 10
|
||||||
state_value = convert_speed(native_value, native_unit, state_unit)
|
state_value = SpeedConverter.convert(native_value, native_unit, state_unit)
|
||||||
|
|
||||||
entity0 = await create_entity(
|
entity0 = await create_entity(
|
||||||
hass, native_wind_speed=native_value, native_wind_speed_unit=native_unit
|
hass, native_wind_speed=native_value, native_wind_speed_unit=native_unit
|
||||||
@ -351,7 +353,7 @@ async def test_visibility(
|
|||||||
"""Test visibility."""
|
"""Test visibility."""
|
||||||
hass.config.units = unit_system
|
hass.config.units = unit_system
|
||||||
native_value = 10
|
native_value = 10
|
||||||
state_value = convert_distance(native_value, native_unit, state_unit)
|
state_value = DistanceConverter.convert(native_value, native_unit, state_unit)
|
||||||
|
|
||||||
entity0 = await create_entity(
|
entity0 = await create_entity(
|
||||||
hass, native_visibility=native_value, native_visibility_unit=native_unit
|
hass, native_visibility=native_value, native_visibility_unit=native_unit
|
||||||
@ -413,7 +415,7 @@ async def test_precipitation(
|
|||||||
"""Test precipitation."""
|
"""Test precipitation."""
|
||||||
hass.config.units = unit_system
|
hass.config.units = unit_system
|
||||||
native_value = 30
|
native_value = 30
|
||||||
state_value = convert_distance(native_value, native_unit, state_unit)
|
state_value = DistanceConverter.convert(native_value, native_unit, state_unit)
|
||||||
|
|
||||||
entity0 = await create_entity(
|
entity0 = await create_entity(
|
||||||
hass, native_precipitation=native_value, native_precipitation_unit=native_unit
|
hass, native_precipitation=native_value, native_precipitation_unit=native_unit
|
||||||
@ -554,22 +556,24 @@ async def test_custom_units(hass: HomeAssistant, enable_custom_integrations) ->
|
|||||||
forecast = state.attributes[ATTR_FORECAST][0]
|
forecast = state.attributes[ATTR_FORECAST][0]
|
||||||
|
|
||||||
expected_wind_speed = round(
|
expected_wind_speed = round(
|
||||||
convert_speed(wind_speed_value, wind_speed_unit, SPEED_MILES_PER_HOUR),
|
SpeedConverter.convert(wind_speed_value, wind_speed_unit, SPEED_MILES_PER_HOUR),
|
||||||
ROUNDING_PRECISION,
|
ROUNDING_PRECISION,
|
||||||
)
|
)
|
||||||
expected_temperature = convert_temperature(
|
expected_temperature = TemperatureConverter.convert(
|
||||||
temperature_value, temperature_unit, TEMP_FAHRENHEIT
|
temperature_value, temperature_unit, TEMP_FAHRENHEIT
|
||||||
)
|
)
|
||||||
expected_pressure = round(
|
expected_pressure = round(
|
||||||
convert_pressure(pressure_value, pressure_unit, PRESSURE_INHG),
|
PressureConverter.convert(pressure_value, pressure_unit, PRESSURE_INHG),
|
||||||
ROUNDING_PRECISION,
|
ROUNDING_PRECISION,
|
||||||
)
|
)
|
||||||
expected_visibility = round(
|
expected_visibility = round(
|
||||||
convert_distance(visibility_value, visibility_unit, LENGTH_MILES),
|
DistanceConverter.convert(visibility_value, visibility_unit, LENGTH_MILES),
|
||||||
ROUNDING_PRECISION,
|
ROUNDING_PRECISION,
|
||||||
)
|
)
|
||||||
expected_precipitation = round(
|
expected_precipitation = round(
|
||||||
convert_distance(precipitation_value, precipitation_unit, LENGTH_INCHES),
|
DistanceConverter.convert(
|
||||||
|
precipitation_value, precipitation_unit, LENGTH_INCHES
|
||||||
|
),
|
||||||
ROUNDING_PRECISION,
|
ROUNDING_PRECISION,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -750,22 +754,24 @@ async def test_backwards_compatibility_convert_values(
|
|||||||
state = hass.states.get(entity0.entity_id)
|
state = hass.states.get(entity0.entity_id)
|
||||||
|
|
||||||
expected_wind_speed = round(
|
expected_wind_speed = round(
|
||||||
convert_speed(wind_speed_value, wind_speed_unit, SPEED_MILES_PER_HOUR),
|
SpeedConverter.convert(wind_speed_value, wind_speed_unit, SPEED_MILES_PER_HOUR),
|
||||||
ROUNDING_PRECISION,
|
ROUNDING_PRECISION,
|
||||||
)
|
)
|
||||||
expected_temperature = convert_temperature(
|
expected_temperature = TemperatureConverter.convert(
|
||||||
temperature_value, temperature_unit, TEMP_FAHRENHEIT
|
temperature_value, temperature_unit, TEMP_FAHRENHEIT
|
||||||
)
|
)
|
||||||
expected_pressure = round(
|
expected_pressure = round(
|
||||||
convert_pressure(pressure_value, pressure_unit, PRESSURE_INHG),
|
PressureConverter.convert(pressure_value, pressure_unit, PRESSURE_INHG),
|
||||||
ROUNDING_PRECISION,
|
ROUNDING_PRECISION,
|
||||||
)
|
)
|
||||||
expected_visibility = round(
|
expected_visibility = round(
|
||||||
convert_distance(visibility_value, visibility_unit, LENGTH_MILES),
|
DistanceConverter.convert(visibility_value, visibility_unit, LENGTH_MILES),
|
||||||
ROUNDING_PRECISION,
|
ROUNDING_PRECISION,
|
||||||
)
|
)
|
||||||
expected_precipitation = round(
|
expected_precipitation = round(
|
||||||
convert_distance(precipitation_value, precipitation_unit, LENGTH_INCHES),
|
DistanceConverter.convert(
|
||||||
|
precipitation_value, precipitation_unit, LENGTH_INCHES
|
||||||
|
),
|
||||||
ROUNDING_PRECISION,
|
ROUNDING_PRECISION,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user