mirror of
https://github.com/home-assistant/core.git
synced 2025-12-25 05:26:47 +00:00
Add temperature util, helpers
This commit is contained in:
@@ -23,7 +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
|
||||
import homeassistant.helpers.temperature as temp_helper
|
||||
|
||||
DOMAIN = "homeassistant"
|
||||
|
||||
@@ -673,18 +673,14 @@ class Config(object):
|
||||
return value, unit
|
||||
|
||||
try:
|
||||
if unit == TEMP_CELCIUS:
|
||||
# Convert C to F
|
||||
return (round(temp_util.c_to_f(float(value)), 1),
|
||||
TEMP_FAHRENHEIT)
|
||||
|
||||
# Convert F to C
|
||||
return round(temp_util.f_to_c(float(value)), 1), TEMP_CELCIUS
|
||||
|
||||
except ValueError:
|
||||
# Could not convert value to float
|
||||
temp = float(value)
|
||||
except ValueError: # Could not convert value to float
|
||||
return value, unit
|
||||
|
||||
return (
|
||||
round(temp_helper.convert(temp, unit, self.temperature_unit), 1),
|
||||
self.temperature_unit)
|
||||
|
||||
def as_dict(self):
|
||||
""" Converts config to a dictionary. """
|
||||
time_zone = self.time_zone or date_util.UTC
|
||||
|
||||
Reference in New Issue
Block a user