core/homeassistant/helpers/temperature.py

20 lines
555 B
Python
Raw Normal View History

2015-08-17 05:06:01 +00:00
"""
homeassistant.helpers.temperature
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Methods to help handle temperature in Home Assistant.
"""
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):
""" Converts 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)