core/homeassistant/helpers/temperature.py

14 lines
480 B
Python
Raw Normal View History

2016-03-07 22:39:52 +00:00
"""Methods to help handle temperature in Home Assistant."""
2015-08-17 05:06:01 +00:00
import homeassistant.util.temperature as temp_util
2016-02-19 05:27:50 +00:00
from homeassistant.const import TEMP_CELCIUS
2015-08-17 05:06:01 +00:00
def convert(temperature, unit, to_unit):
2016-03-07 22:39:52 +00:00
"""Convert temperature to correct unit."""
2015-10-23 05:04:37 +00:00
if unit == to_unit or unit is None or to_unit is None:
2015-08-17 05:06:01 +00:00
return temperature
elif unit == TEMP_CELCIUS:
return temp_util.celcius_to_fahrenheit(temperature)
return temp_util.fahrenheit_to_celcius(temperature)