Use unit_conversion in components (#79204)
* Use unit_conversion in components * Two more
This commit is contained in:
parent
f76eeaeea1
commit
24c26dc032
19 changed files with 84 additions and 63 deletions
|
@ -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"))
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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"]),
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
),
|
||||
),
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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."""
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue