2016-03-07 23:39:52 +01:00
|
|
|
"""Methods to help handle temperature in Home Assistant."""
|
2015-08-16 22:06:01 -07:00
|
|
|
import homeassistant.util.temperature as temp_util
|
2016-04-19 20:30:44 -07:00
|
|
|
from homeassistant.const import TEMP_CELSIUS
|
2015-08-16 22:06:01 -07:00
|
|
|
|
|
|
|
|
|
|
|
def convert(temperature, unit, to_unit):
|
2016-03-07 23:39:52 +01:00
|
|
|
"""Convert temperature to correct unit."""
|
2015-10-22 22:04:37 -07:00
|
|
|
if unit == to_unit or unit is None or to_unit is None:
|
2015-08-16 22:06:01 -07:00
|
|
|
return temperature
|
2016-04-19 20:30:44 -07:00
|
|
|
elif unit == TEMP_CELSIUS:
|
|
|
|
return temp_util.celsius_to_fahrenheit(temperature)
|
2015-08-16 22:06:01 -07:00
|
|
|
|
2016-04-19 20:30:44 -07:00
|
|
|
return temp_util.fahrenheit_to_celsius(temperature)
|