diff --git a/homeassistant/core.py b/homeassistant/core.py index afc4ea8375fb..76ff46cfe8bd 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -23,6 +23,7 @@ from homeassistant.const import ( TEMP_CELCIUS, TEMP_FAHRENHEIT, ATTR_FRIENDLY_NAME) import homeassistant.util as util import homeassistant.util.dt as date_util +import homeassistant.util.temperature as temp_util DOMAIN = "homeassistant" @@ -674,10 +675,11 @@ class Config(object): try: if unit == TEMP_CELCIUS: # Convert C to F - return round(float(value) * 1.8 + 32.0, 1), TEMP_FAHRENHEIT + return (round(temp_util.c_to_f(float(value)), 1), + TEMP_FAHRENHEIT) # Convert F to C - return round((float(value)-32.0)/1.8, 1), TEMP_CELCIUS + return round(temp_util.f_to_c(float(value)), 1), TEMP_CELCIUS except ValueError: # Could not convert value to float diff --git a/homeassistant/util/temperature.py b/homeassistant/util/temperature.py new file mode 100644 index 000000000000..4cd0e1ed1d04 --- /dev/null +++ b/homeassistant/util/temperature.py @@ -0,0 +1,16 @@ +""" +homeassistant.util.temperature +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Temperature util functions. +""" + + +def f_to_c(fahrenheit): + """ Convert a Fahrenheit temperature to Celcius. """ + return (fahrenheit - 32.0) / 1.8 + + +def c_to_f(celcius): + """ Convert a Celcius temperature to Fahrenheit. """ + return celcius * 1.8 + 32.0