mirror of
https://github.com/home-assistant/core
synced 2024-09-30 20:21:34 +00:00
Extract temperature util
This commit is contained in:
parent
dda399fc76
commit
b61b3c611d
|
@ -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
|
||||
|
|
16
homeassistant/util/temperature.py
Normal file
16
homeassistant/util/temperature.py
Normal file
|
@ -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
|
Loading…
Reference in a new issue