2016-03-07 22:20:48 +00:00
|
|
|
"""Temperature util functions."""
|
2022-09-22 16:31:50 +00:00
|
|
|
from homeassistant.const import ( # pylint: disable=unused-import # noqa: F401
|
2019-07-31 19:25:30 +00:00
|
|
|
TEMP_CELSIUS,
|
|
|
|
TEMP_FAHRENHEIT,
|
2021-06-30 12:17:58 +00:00
|
|
|
TEMP_KELVIN,
|
2019-07-31 19:25:30 +00:00
|
|
|
TEMPERATURE,
|
2019-12-09 15:42:10 +00:00
|
|
|
UNIT_NOT_RECOGNIZED_TEMPLATE,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2015-08-17 04:36:33 +00:00
|
|
|
|
2022-09-22 16:31:50 +00:00
|
|
|
from .unit_conversion import TemperatureConverter
|
2022-03-30 13:43:04 +00:00
|
|
|
|
2022-09-22 16:31:50 +00:00
|
|
|
VALID_UNITS = TemperatureConverter.VALID_UNITS
|
2022-09-22 06:50:08 +00:00
|
|
|
|
2016-04-20 03:30:44 +00:00
|
|
|
|
2018-03-30 06:49:08 +00:00
|
|
|
def fahrenheit_to_celsius(fahrenheit: float, interval: bool = False) -> float:
|
2017-04-30 05:04:49 +00:00
|
|
|
"""Convert a temperature in Fahrenheit to Celsius."""
|
2022-09-22 16:31:50 +00:00
|
|
|
# Need to add warning when core migration finished
|
|
|
|
return TemperatureConverter.fahrenheit_to_celsius(fahrenheit, interval)
|
2015-08-17 04:36:33 +00:00
|
|
|
|
|
|
|
|
2021-06-30 12:17:58 +00:00
|
|
|
def kelvin_to_celsius(kelvin: float, interval: bool = False) -> float:
|
|
|
|
"""Convert a temperature in Kelvin to Celsius."""
|
2022-09-22 16:31:50 +00:00
|
|
|
# Need to add warning when core migration finished
|
|
|
|
return TemperatureConverter.kelvin_to_celsius(kelvin, interval)
|
2021-06-30 12:17:58 +00:00
|
|
|
|
|
|
|
|
2018-03-30 06:49:08 +00:00
|
|
|
def celsius_to_fahrenheit(celsius: float, interval: bool = False) -> float:
|
2017-04-30 05:04:49 +00:00
|
|
|
"""Convert a temperature in Celsius to Fahrenheit."""
|
2022-09-22 16:31:50 +00:00
|
|
|
# Need to add warning when core migration finished
|
|
|
|
return TemperatureConverter.celsius_to_fahrenheit(celsius, interval)
|
2016-07-31 20:24:49 +00:00
|
|
|
|
|
|
|
|
2021-06-30 12:17:58 +00:00
|
|
|
def celsius_to_kelvin(celsius: float, interval: bool = False) -> float:
|
|
|
|
"""Convert a temperature in Celsius to Fahrenheit."""
|
2022-09-22 16:31:50 +00:00
|
|
|
# Need to add warning when core migration finished
|
|
|
|
return TemperatureConverter.celsius_to_kelvin(celsius, interval)
|
2021-06-30 12:17:58 +00:00
|
|
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
def convert(
|
2021-07-20 12:13:51 +00:00
|
|
|
temperature: float, from_unit: str, to_unit: str, interval: bool = False
|
2019-07-31 19:25:30 +00:00
|
|
|
) -> float:
|
2016-07-31 20:24:49 +00:00
|
|
|
"""Convert a temperature from one unit to another."""
|
2022-09-22 16:31:50 +00:00
|
|
|
# Need to add warning when core migration finished
|
|
|
|
return TemperatureConverter.convert(
|
|
|
|
temperature, from_unit, to_unit, interval=interval
|
|
|
|
)
|