diff --git a/homeassistant/components/alexa/handlers.py b/homeassistant/components/alexa/handlers.py index c10f7a50369..73410ba06d2 100644 --- a/homeassistant/components/alexa/handlers.py +++ b/homeassistant/components/alexa/handlers.py @@ -50,10 +50,9 @@ from homeassistant.const import ( TEMP_FAHRENHEIT, ) from homeassistant.helpers import network -import homeassistant.util.color as color_util +from homeassistant.util import color as color_util, dt as dt_util from homeassistant.util.decorator import Registry -import homeassistant.util.dt as dt_util -from homeassistant.util.temperature import convert as convert_temperature +from homeassistant.util.unit_conversion import TemperatureConverter from .config import AbstractConfig from .const import ( @@ -820,7 +819,7 @@ def temperature_from_object(hass, temp_obj, interval=False): # convert to Celsius if absolute temperature temp -= 273.15 - return convert_temperature(temp, from_unit, to_unit, interval) + return TemperatureConverter.convert(temp, from_unit, to_unit, interval=interval) @HANDLERS.register(("Alexa.ThermostatController", "SetTargetTemperature")) diff --git a/homeassistant/components/citybikes/sensor.py b/homeassistant/components/citybikes/sensor.py index b9085e24f45..5074378adca 100644 --- a/homeassistant/components/citybikes/sensor.py +++ b/homeassistant/components/citybikes/sensor.py @@ -35,7 +35,8 @@ from homeassistant.helpers.entity import async_generate_entity_id from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.event import async_track_time_interval from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType -from homeassistant.util import distance, location +from homeassistant.util import location +from homeassistant.util.unit_conversion import DistanceConverter _LOGGER = logging.getLogger(__name__) @@ -170,7 +171,7 @@ async def async_setup_platform( radius = config.get(CONF_RADIUS, 0) name = config[CONF_NAME] if not hass.config.units.is_metric: - radius = distance.convert(radius, LENGTH_FEET, LENGTH_METERS) + radius = DistanceConverter.convert(radius, LENGTH_FEET, LENGTH_METERS) # Create a single instance of CityBikesNetworks. networks = hass.data.setdefault(CITYBIKES_NETWORKS, CityBikesNetworks(hass)) diff --git a/homeassistant/components/climate/__init__.py b/homeassistant/components/climate/__init__.py index 4ed875f2d31..67348d38625 100644 --- a/homeassistant/components/climate/__init__.py +++ b/homeassistant/components/climate/__init__.py @@ -31,7 +31,7 @@ from homeassistant.helpers.entity import Entity, EntityDescription from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.temperature import display_temp as show_temp from homeassistant.helpers.typing import ConfigType -from homeassistant.util.temperature import convert as convert_temperature +from homeassistant.util.unit_conversion import TemperatureConverter from .const import ( # noqa: F401 ATTR_AUX_HEAT, @@ -560,7 +560,7 @@ class ClimateEntity(Entity): def min_temp(self) -> float: """Return the minimum temperature.""" if not hasattr(self, "_attr_min_temp"): - return convert_temperature( + return TemperatureConverter.convert( DEFAULT_MIN_TEMP, TEMP_CELSIUS, self.temperature_unit ) return self._attr_min_temp @@ -569,7 +569,7 @@ class ClimateEntity(Entity): def max_temp(self) -> float: """Return the maximum temperature.""" if not hasattr(self, "_attr_max_temp"): - return convert_temperature( + return TemperatureConverter.convert( DEFAULT_MAX_TEMP, TEMP_CELSIUS, self.temperature_unit ) return self._attr_max_temp @@ -604,7 +604,7 @@ async def async_service_temperature_set( for value, temp in service_call.data.items(): if value in CONVERTIBLE_ATTRIBUTE: - kwargs[value] = convert_temperature( + kwargs[value] = TemperatureConverter.convert( temp, hass.config.units.temperature_unit, entity.temperature_unit ) else: diff --git a/homeassistant/components/ecobee/climate.py b/homeassistant/components/ecobee/climate.py index c5490c55850..16870d76902 100644 --- a/homeassistant/components/ecobee/climate.py +++ b/homeassistant/components/ecobee/climate.py @@ -33,7 +33,7 @@ from homeassistant.helpers import entity_platform import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.util.temperature import convert +from homeassistant.util.unit_conversion import TemperatureConverter from .const import _LOGGER, DOMAIN, ECOBEE_MODEL_TO_NAME, MANUFACTURER from .util import ecobee_date, ecobee_time @@ -763,12 +763,12 @@ class Thermostat(ClimateEntity): def create_vacation(self, service_data): """Create a vacation with user-specified parameters.""" vacation_name = service_data[ATTR_VACATION_NAME] - cool_temp = convert( + cool_temp = TemperatureConverter.convert( service_data[ATTR_COOL_TEMP], self.hass.config.units.temperature_unit, TEMP_FAHRENHEIT, ) - heat_temp = convert( + heat_temp = TemperatureConverter.convert( service_data[ATTR_HEAT_TEMP], self.hass.config.units.temperature_unit, TEMP_FAHRENHEIT, diff --git a/homeassistant/components/life360/coordinator.py b/homeassistant/components/life360/coordinator.py index 3bee1b5827e..edb86e9727a 100644 --- a/homeassistant/components/life360/coordinator.py +++ b/homeassistant/components/life360/coordinator.py @@ -21,8 +21,8 @@ from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryAuthFailed from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed -from homeassistant.util.distance import convert -import homeassistant.util.dt as dt_util +from homeassistant.util import dt as dt_util +from homeassistant.util.unit_conversion import DistanceConverter from .const import ( COMM_TIMEOUT, @@ -207,7 +207,9 @@ class Life360DataUpdateCoordinator(DataUpdateCoordinator[Life360Data]): speed = max(0, float(loc["speed"]) * SPEED_FACTOR_MPH) if self._hass.config.units.is_metric: - speed = convert(speed, LENGTH_MILES, LENGTH_KILOMETERS) + speed = DistanceConverter.convert( + speed, LENGTH_MILES, LENGTH_KILOMETERS + ) data.members[member_id] = Life360Member( address, @@ -218,7 +220,11 @@ class Life360DataUpdateCoordinator(DataUpdateCoordinator[Life360Data]): member["avatar"], # Life360 reports accuracy in feet, but Device Tracker expects # gps_accuracy in meters. - round(convert(float(loc["accuracy"]), LENGTH_FEET, LENGTH_METERS)), + round( + DistanceConverter.convert( + float(loc["accuracy"]), LENGTH_FEET, LENGTH_METERS + ) + ), dt_util.utc_from_timestamp(int(loc["timestamp"])), float(loc["latitude"]), float(loc["longitude"]), diff --git a/homeassistant/components/met/__init__.py b/homeassistant/components/met/__init__.py index b4889a62411..2857c057482 100644 --- a/homeassistant/components/met/__init__.py +++ b/homeassistant/components/met/__init__.py @@ -24,8 +24,8 @@ from homeassistant.core import Event, HomeAssistant from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed -from homeassistant.util.distance import convert as convert_distance -import homeassistant.util.dt as dt_util +from homeassistant.util import dt as dt_util +from homeassistant.util.unit_conversion import DistanceConverter from .const import ( CONF_TRACK_HOME, @@ -160,7 +160,7 @@ class MetWeatherData: if not self._is_metric: elevation = int( - round(convert_distance(elevation, LENGTH_FEET, LENGTH_METERS)) + round(DistanceConverter.convert(elevation, LENGTH_FEET, LENGTH_METERS)) ) coordinates = { diff --git a/homeassistant/components/nws/sensor.py b/homeassistant/components/nws/sensor.py index ec53d909561..1e062bf3d36 100644 --- a/homeassistant/components/nws/sensor.py +++ b/homeassistant/components/nws/sensor.py @@ -17,10 +17,12 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.update_coordinator import CoordinatorEntity -from homeassistant.util.distance import convert as convert_distance from homeassistant.util.dt import utcnow -from homeassistant.util.pressure import convert as convert_pressure -from homeassistant.util.speed import convert as convert_speed +from homeassistant.util.unit_conversion import ( + DistanceConverter, + PressureConverter, + SpeedConverter, +) from . import base_unique_id, device_info from .const import ( @@ -91,12 +93,16 @@ class NWSSensor(CoordinatorEntity, SensorEntity): unit_of_measurement = self.native_unit_of_measurement if unit_of_measurement == SPEED_MILES_PER_HOUR: return round( - convert_speed(value, SPEED_KILOMETERS_PER_HOUR, SPEED_MILES_PER_HOUR) + SpeedConverter.convert( + value, SPEED_KILOMETERS_PER_HOUR, SPEED_MILES_PER_HOUR + ) ) if unit_of_measurement == LENGTH_MILES: - return round(convert_distance(value, LENGTH_METERS, LENGTH_MILES)) + return round(DistanceConverter.convert(value, LENGTH_METERS, LENGTH_MILES)) if unit_of_measurement == PRESSURE_INHG: - return round(convert_pressure(value, PRESSURE_PA, PRESSURE_INHG), 2) + return round( + PressureConverter.convert(value, PRESSURE_PA, PRESSURE_INHG), 2 + ) if unit_of_measurement == TEMP_CELSIUS: return round(value, 1) if unit_of_measurement == PERCENTAGE: diff --git a/homeassistant/components/nws/weather.py b/homeassistant/components/nws/weather.py index eb6f7a4f39d..4684714d58c 100644 --- a/homeassistant/components/nws/weather.py +++ b/homeassistant/components/nws/weather.py @@ -25,8 +25,7 @@ from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.util.dt import utcnow -from homeassistant.util.speed import convert as convert_speed -from homeassistant.util.temperature import convert as convert_temperature +from homeassistant.util.unit_conversion import SpeedConverter, TemperatureConverter from . import base_unique_id, device_info from .const import ( @@ -235,7 +234,7 @@ class NWSWeather(WeatherEntity): } if (temp := forecast_entry.get("temperature")) is not None: - data[ATTR_FORECAST_NATIVE_TEMP] = convert_temperature( + data[ATTR_FORECAST_NATIVE_TEMP] = TemperatureConverter.convert( temp, TEMP_FAHRENHEIT, TEMP_CELSIUS ) else: @@ -255,7 +254,7 @@ class NWSWeather(WeatherEntity): data[ATTR_FORECAST_WIND_BEARING] = forecast_entry.get("windBearing") wind_speed = forecast_entry.get("windSpeedAvg") if wind_speed is not None: - data[ATTR_FORECAST_NATIVE_WIND_SPEED] = convert_speed( + data[ATTR_FORECAST_NATIVE_WIND_SPEED] = SpeedConverter.convert( wind_speed, SPEED_MILES_PER_HOUR, SPEED_KILOMETERS_PER_HOUR ) else: diff --git a/homeassistant/components/opensky/sensor.py b/homeassistant/components/opensky/sensor.py index 1b480e997d8..66579eb8173 100644 --- a/homeassistant/components/opensky/sensor.py +++ b/homeassistant/components/opensky/sensor.py @@ -22,7 +22,8 @@ from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType -from homeassistant.util import distance as util_distance, location as util_location +from homeassistant.util import location as util_location +from homeassistant.util.unit_conversion import DistanceConverter CONF_ALTITUDE = "altitude" @@ -105,7 +106,9 @@ class OpenSkySensor(SensorEntity): self._session = requests.Session() self._latitude = latitude self._longitude = longitude - self._radius = util_distance.convert(radius, LENGTH_KILOMETERS, LENGTH_METERS) + self._radius = DistanceConverter.convert( + radius, LENGTH_KILOMETERS, LENGTH_METERS + ) self._altitude = altitude self._state = 0 self._hass = hass diff --git a/homeassistant/components/openweathermap/weather_update_coordinator.py b/homeassistant/components/openweathermap/weather_update_coordinator.py index 98c3b56fb5e..b5435c92680 100644 --- a/homeassistant/components/openweathermap/weather_update_coordinator.py +++ b/homeassistant/components/openweathermap/weather_update_coordinator.py @@ -12,7 +12,7 @@ from homeassistant.components.weather import ( from homeassistant.helpers import sun from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed from homeassistant.util import dt -from homeassistant.util.temperature import kelvin_to_celsius +from homeassistant.util.unit_conversion import TemperatureConverter from .const import ( ATTR_API_CLOUDS, @@ -191,7 +191,7 @@ class WeatherUpdateCoordinator(DataUpdateCoordinator): def _fmt_dewpoint(dewpoint): """Format the dewpoint data.""" if dewpoint is not None: - return round(kelvin_to_celsius(dewpoint), 1) + return round(TemperatureConverter.kelvin_to_celsius(dewpoint), 1) return None @staticmethod diff --git a/homeassistant/components/prometheus/__init__.py b/homeassistant/components/prometheus/__init__.py index d247af922d3..e5dcebd3ca9 100644 --- a/homeassistant/components/prometheus/__init__.py +++ b/homeassistant/components/prometheus/__init__.py @@ -40,7 +40,7 @@ import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_registry import EVENT_ENTITY_REGISTRY_UPDATED from homeassistant.helpers.entity_values import EntityValues from homeassistant.helpers.typing import ConfigType -from homeassistant.util.temperature import fahrenheit_to_celsius +from homeassistant.util.unit_conversion import TemperatureConverter _LOGGER = logging.getLogger(__name__) @@ -348,7 +348,7 @@ class PrometheusMetrics: with suppress(ValueError): value = self.state_as_number(state) if state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_FAHRENHEIT: - value = fahrenheit_to_celsius(value) + value = TemperatureConverter.fahrenheit_to_celsius(value) metric.labels(**self._labels(state)).set(value) def _handle_device_tracker(self, state): @@ -394,7 +394,7 @@ class PrometheusMetrics: def _handle_climate_temp(self, state, attr, metric_name, metric_description): if temp := state.attributes.get(attr): if self._climate_units == TEMP_FAHRENHEIT: - temp = fahrenheit_to_celsius(temp) + temp = TemperatureConverter.fahrenheit_to_celsius(temp) metric = self._metric( metric_name, self.prometheus_cli.Gauge, @@ -507,7 +507,7 @@ class PrometheusMetrics: try: value = self.state_as_number(state) if state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_FAHRENHEIT: - value = fahrenheit_to_celsius(value) + value = TemperatureConverter.fahrenheit_to_celsius(value) _metric.labels(**self._labels(state)).set(value) except ValueError: pass diff --git a/homeassistant/components/proximity/__init__.py b/homeassistant/components/proximity/__init__.py index 7a54b11ef34..cf99f4fa503 100644 --- a/homeassistant/components/proximity/__init__.py +++ b/homeassistant/components/proximity/__init__.py @@ -22,8 +22,8 @@ import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import Entity from homeassistant.helpers.event import track_state_change from homeassistant.helpers.typing import ConfigType -from homeassistant.util.distance import convert from homeassistant.util.location import distance +from homeassistant.util.unit_conversion import DistanceConverter _LOGGER = logging.getLogger(__name__) @@ -235,7 +235,10 @@ class Proximity(Entity): if not proximity: continue distances_to_zone[device] = round( - convert(proximity, LENGTH_METERS, self.unit_of_measurement), 1 + DistanceConverter.convert( + proximity, LENGTH_METERS, self.unit_of_measurement + ), + 1, ) # Loop through each of the distances collected and work out the diff --git a/homeassistant/components/sensibo/climate.py b/homeassistant/components/sensibo/climate.py index 36047fe0ddd..9c3c5c111f5 100644 --- a/homeassistant/components/sensibo/climate.py +++ b/homeassistant/components/sensibo/climate.py @@ -23,7 +23,7 @@ from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import config_validation as cv, entity_platform from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.util.temperature import convert as convert_temperature +from homeassistant.util.unit_conversion import TemperatureConverter from .const import DOMAIN from .coordinator import SensiboDataUpdateCoordinator @@ -169,7 +169,7 @@ class SensiboClimate(SensiboDeviceBaseEntity, ClimateEntity): def current_temperature(self) -> float | None: """Return the current temperature.""" if self.device_data.temp: - return convert_temperature( + return TemperatureConverter.convert( self.device_data.temp, TEMP_CELSIUS, self.temperature_unit, diff --git a/homeassistant/components/smarttub/climate.py b/homeassistant/components/smarttub/climate.py index 758cffe7fa8..0afebbd6433 100644 --- a/homeassistant/components/smarttub/climate.py +++ b/homeassistant/components/smarttub/climate.py @@ -17,7 +17,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.util.temperature import convert as convert_temperature +from homeassistant.util.unit_conversion import TemperatureConverter from .const import DEFAULT_MAX_TEMP, DEFAULT_MIN_TEMP, DOMAIN, SMARTTUB_CONTROLLER from .entity import SmartTubEntity @@ -87,13 +87,17 @@ class SmartTubThermostat(SmartTubEntity, ClimateEntity): def min_temp(self): """Return the minimum temperature.""" min_temp = DEFAULT_MIN_TEMP - return convert_temperature(min_temp, TEMP_CELSIUS, self.temperature_unit) + return TemperatureConverter.convert( + min_temp, TEMP_CELSIUS, self.temperature_unit + ) @property def max_temp(self): """Return the maximum temperature.""" max_temp = DEFAULT_MAX_TEMP - return convert_temperature(max_temp, TEMP_CELSIUS, self.temperature_unit) + return TemperatureConverter.convert( + max_temp, TEMP_CELSIUS, self.temperature_unit + ) @property def preset_mode(self): diff --git a/homeassistant/components/subaru/sensor.py b/homeassistant/components/subaru/sensor.py index ba96902f6fb..f1a1ea96382 100644 --- a/homeassistant/components/subaru/sensor.py +++ b/homeassistant/components/subaru/sensor.py @@ -20,14 +20,13 @@ from homeassistant.const import ( ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.util.distance import convert as dist_convert +from homeassistant.util.unit_conversion import DistanceConverter, VolumeConverter from homeassistant.util.unit_system import ( IMPERIAL_SYSTEM, LENGTH_UNITS, PRESSURE_UNITS, TEMPERATURE_UNITS, ) -from homeassistant.util.volume import convert as vol_convert from .const import ( API_GEN_2, @@ -42,8 +41,8 @@ from .const import ( ) from .entity import SubaruEntity -L_PER_GAL = vol_convert(1, VOLUME_GALLONS, VOLUME_LITERS) -KM_PER_MI = dist_convert(1, LENGTH_MILES, LENGTH_KILOMETERS) +L_PER_GAL = VolumeConverter.convert(1, VOLUME_GALLONS, VOLUME_LITERS) +KM_PER_MI = DistanceConverter.convert(1, LENGTH_MILES, LENGTH_KILOMETERS) # Fuel Economy Constants FUEL_CONSUMPTION_L_PER_100KM = "L/100km" diff --git a/homeassistant/components/tomorrowio/sensor.py b/homeassistant/components/tomorrowio/sensor.py index ea114af0544..b2179cd60f5 100644 --- a/homeassistant/components/tomorrowio/sensor.py +++ b/homeassistant/components/tomorrowio/sensor.py @@ -38,8 +38,7 @@ from homeassistant.const import ( from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.util import slugify -from homeassistant.util.distance import convert as distance_convert -from homeassistant.util.speed import convert as speed_convert +from homeassistant.util.unit_conversion import DistanceConverter, SpeedConverter from . import TomorrowioDataUpdateCoordinator, TomorrowioEntity from .const import ( @@ -135,7 +134,7 @@ SENSOR_TYPES = ( name="Cloud Base", unit_imperial=LENGTH_MILES, unit_metric=LENGTH_KILOMETERS, - imperial_conversion=lambda val: distance_convert( + imperial_conversion=lambda val: DistanceConverter.convert( val, LENGTH_KILOMETERS, LENGTH_MILES ), ), @@ -145,7 +144,7 @@ SENSOR_TYPES = ( name="Cloud Ceiling", unit_imperial=LENGTH_MILES, unit_metric=LENGTH_KILOMETERS, - imperial_conversion=lambda val: distance_convert( + imperial_conversion=lambda val: DistanceConverter.convert( val, LENGTH_KILOMETERS, LENGTH_MILES ), ), @@ -160,7 +159,7 @@ SENSOR_TYPES = ( name="Wind Gust", unit_imperial=SPEED_MILES_PER_HOUR, unit_metric=SPEED_METERS_PER_SECOND, - imperial_conversion=lambda val: speed_convert( + imperial_conversion=lambda val: SpeedConverter.convert( val, SPEED_METERS_PER_SECOND, SPEED_MILES_PER_HOUR ), ), diff --git a/homeassistant/components/water_heater/__init__.py b/homeassistant/components/water_heater/__init__.py index 8881b3babd4..4712d4a2701 100644 --- a/homeassistant/components/water_heater/__init__.py +++ b/homeassistant/components/water_heater/__init__.py @@ -34,7 +34,7 @@ from homeassistant.helpers.entity import Entity, EntityDescription from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.temperature import display_temp as show_temp from homeassistant.helpers.typing import ConfigType -from homeassistant.util.temperature import convert as convert_temperature +from homeassistant.util.unit_conversion import TemperatureConverter DEFAULT_MIN_TEMP = 110 DEFAULT_MAX_TEMP = 140 @@ -328,7 +328,7 @@ class WaterHeaterEntity(Entity): """Return the minimum temperature.""" if hasattr(self, "_attr_min_temp"): return self._attr_min_temp - return convert_temperature( + return TemperatureConverter.convert( DEFAULT_MIN_TEMP, TEMP_FAHRENHEIT, self.temperature_unit ) @@ -337,7 +337,7 @@ class WaterHeaterEntity(Entity): """Return the maximum temperature.""" if hasattr(self, "_attr_max_temp"): return self._attr_max_temp - return convert_temperature( + return TemperatureConverter.convert( DEFAULT_MAX_TEMP, TEMP_FAHRENHEIT, self.temperature_unit ) @@ -361,7 +361,7 @@ async def async_service_temperature_set( for value, temp in service.data.items(): if value in CONVERTIBLE_ATTRIBUTE: - kwargs[value] = convert_temperature( + kwargs[value] = TemperatureConverter.convert( temp, hass.config.units.temperature_unit, entity.temperature_unit ) else: diff --git a/homeassistant/components/zwave_js/climate.py b/homeassistant/components/zwave_js/climate.py index 264bb5e6ee8..07119d365e0 100644 --- a/homeassistant/components/zwave_js/climate.py +++ b/homeassistant/components/zwave_js/climate.py @@ -43,7 +43,7 @@ from homeassistant.const import ( from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.util.temperature import convert as convert_temperature +from homeassistant.util.unit_conversion import TemperatureConverter from .const import DATA_CLIENT, DOMAIN from .discovery import ZwaveDiscoveryInfo @@ -388,7 +388,7 @@ class ZWaveClimate(ZWaveBaseEntity, ClimateEntity): except (IndexError, ValueError, TypeError): pass - return convert_temperature(min_temp, base_unit, self.temperature_unit) + return TemperatureConverter.convert(min_temp, base_unit, self.temperature_unit) @property def max_temp(self) -> float: @@ -404,7 +404,7 @@ class ZWaveClimate(ZWaveBaseEntity, ClimateEntity): except (IndexError, ValueError, TypeError): pass - return convert_temperature(max_temp, base_unit, self.temperature_unit) + return TemperatureConverter.convert(max_temp, base_unit, self.temperature_unit) async def async_set_fan_mode(self, fan_mode: str) -> None: """Set new target fan mode.""" diff --git a/homeassistant/helpers/temperature.py b/homeassistant/helpers/temperature.py index e0f089e93b9..5a35f1bee13 100644 --- a/homeassistant/helpers/temperature.py +++ b/homeassistant/helpers/temperature.py @@ -5,7 +5,7 @@ from numbers import Number from homeassistant.const import PRECISION_HALVES, PRECISION_TENTHS from homeassistant.core import HomeAssistant -from homeassistant.util.temperature import convert as convert_temperature +from homeassistant.util.unit_conversion import TemperatureConverter def display_temp( @@ -24,7 +24,9 @@ def display_temp( raise TypeError(f"Temperature is not a number: {temperature}") if temperature_unit != ha_unit: - temperature = convert_temperature(temperature, temperature_unit, ha_unit) + temperature = TemperatureConverter.convert( + temperature, temperature_unit, ha_unit + ) # Round in the units appropriate if precision == PRECISION_HALVES: