Make thermostat more robust

This commit is contained in:
Paulus Schoutsen 2015-10-11 18:16:55 -07:00
parent f081f7c4ff
commit bf1970b78c

View File

@ -136,22 +136,16 @@ class ThermostatDevice(Entity):
def state_attributes(self): def state_attributes(self):
""" Returns optional state attributes. """ """ Returns optional state attributes. """
thermostat_unit = self.unit_of_measurement
user_unit = self.hass.config.temperature_unit
data = { data = {
ATTR_CURRENT_TEMPERATURE: round(convert( ATTR_CURRENT_TEMPERATURE:
self.current_temperature, thermostat_unit, user_unit), 1), self._convert(self.current_temperature, 1),
ATTR_MIN_TEMP: round(convert( ATTR_MIN_TEMP: self._convert(self.min_temp, 0),
self.min_temp, thermostat_unit, user_unit), 0), ATTR_MAX_TEMP: self._convert(self.max_temp, 0),
ATTR_MAX_TEMP: round(convert( ATTR_TEMPERATURE: self._convert(self.target_temperature, 0),
self.max_temp, thermostat_unit, user_unit), 0), ATTR_TEMPERATURE_LOW:
ATTR_TEMPERATURE: round(convert( self._convert(self.target_temperature_low, 0),
self.target_temperature, thermostat_unit, user_unit), 0), ATTR_TEMPERATURE_HIGH:
ATTR_TEMPERATURE_LOW: round(convert( self._convert(self.target_temperature_high, 0),
self.target_temperature_low, thermostat_unit, user_unit), 0),
ATTR_TEMPERATURE_HIGH: round(convert(
self.target_temperature_high, thermostat_unit, user_unit), 0),
} }
operation = self.operation operation = self.operation
@ -228,3 +222,14 @@ class ThermostatDevice(Entity):
def max_temp(self): def max_temp(self):
""" Return maxmum temperature. """ """ Return maxmum temperature. """
return convert(35, TEMP_CELCIUS, self.unit_of_measurement) return convert(35, TEMP_CELCIUS, self.unit_of_measurement)
def _convert(self, temp, round_dec=None):
""" Convert temperature from this thermost into user preferred
temperature. """
if temp is None:
return None
value = convert(temp, self.unit_of_measurement,
self.hass.config.temperature_unit)
return value if round_dec is None else round(value, round_dec)