mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 22:37:11 +00:00
Have thermostat class make all necessary unit conversions
This commit is contained in:
parent
6647894c36
commit
e15eb90b33
@ -10,6 +10,7 @@ from homeassistant.helpers.entity_component import EntityComponent
|
||||
|
||||
import homeassistant.util as util
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.temperature import convert
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID, ATTR_TEMPERATURE, STATE_ON, STATE_OFF, TEMP_CELCIUS)
|
||||
|
||||
@ -86,7 +87,9 @@ def setup(hass, config):
|
||||
return
|
||||
|
||||
for thermostat in target_thermostats:
|
||||
thermostat.set_temperature(temperature)
|
||||
thermostat.set_temperature(convert(
|
||||
temperature, hass.config.temperature_unit,
|
||||
thermostat.unit_of_measurement))
|
||||
|
||||
for thermostat in target_thermostats:
|
||||
thermostat.update_ha_state(True)
|
||||
@ -118,9 +121,20 @@ class ThermostatDevice(Entity):
|
||||
@property
|
||||
def state_attributes(self):
|
||||
""" Returns optional state attributes. """
|
||||
|
||||
thermostat_unit = self.unit_of_measurement
|
||||
user_unit = self.hass.config.temperature_unit
|
||||
|
||||
data = {
|
||||
ATTR_CURRENT_TEMPERATURE: self.hass.config.temperature(
|
||||
self.current_temperature, self.unit_of_measurement)[0]
|
||||
ATTR_CURRENT_TEMPERATURE: round(convert(self.current_temperature,
|
||||
thermostat_unit,
|
||||
user_unit), 1),
|
||||
ATTR_MIN_TEMP: round(convert(self.min_temp,
|
||||
thermostat_unit,
|
||||
user_unit), 0),
|
||||
ATTR_MAX_TEMP: round(convert(self.max_temp,
|
||||
thermostat_unit,
|
||||
user_unit), 0)
|
||||
}
|
||||
|
||||
is_away = self.is_away_mode_on
|
||||
@ -133,11 +147,13 @@ class ThermostatDevice(Entity):
|
||||
if device_attr is not None:
|
||||
data.update(device_attr)
|
||||
|
||||
data[ATTR_MIN_TEMP] = self.min_temp
|
||||
data[ATTR_MAX_TEMP] = self.max_temp
|
||||
|
||||
return data
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
""" Unit of measurement this thermostat expresses itself in. """
|
||||
return NotImplementedError
|
||||
|
||||
@property
|
||||
def current_temperature(self):
|
||||
""" Returns the current temperature. """
|
||||
@ -171,9 +187,9 @@ class ThermostatDevice(Entity):
|
||||
@property
|
||||
def min_temp(self):
|
||||
""" Return minimum temperature. """
|
||||
return self.hass.config.temperature(7, TEMP_CELCIUS)[0]
|
||||
return convert(7, TEMP_CELCIUS, self.unit_of_measurement)
|
||||
|
||||
@property
|
||||
def max_temp(self):
|
||||
""" Return maxmum temperature. """
|
||||
return self.hass.config.temperature(35, TEMP_CELCIUS)[0]
|
||||
return convert(35, TEMP_CELCIUS, self.unit_of_measurement)
|
||||
|
@ -4,7 +4,6 @@ Adds support for Nest thermostats.
|
||||
import logging
|
||||
|
||||
from homeassistant.components.thermostat import ThermostatDevice
|
||||
from homeassistant.helpers.temperature import convert
|
||||
from homeassistant.const import (CONF_USERNAME, CONF_PASSWORD, TEMP_CELCIUS)
|
||||
|
||||
REQUIREMENTS = ['python-nest>=2.4.0']
|
||||
@ -63,7 +62,7 @@ class NestThermostat(ThermostatDevice):
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
""" Returns the unit of measurement. """
|
||||
""" Unit of measurement this thermostat expresses itself in. """
|
||||
return TEMP_CELCIUS
|
||||
|
||||
@property
|
||||
@ -107,9 +106,7 @@ class NestThermostat(ThermostatDevice):
|
||||
return self.structure.away
|
||||
|
||||
def set_temperature(self, temperature):
|
||||
""" Set new target temperature ensuring it is in proper units """
|
||||
temperature = convert(temperature, self.hass.config.temperature_unit,
|
||||
self.unit_of_measurement)
|
||||
""" Set new target temperature """
|
||||
self.device.target = temperature
|
||||
|
||||
def turn_away_mode_on(self):
|
||||
@ -127,7 +124,7 @@ class NestThermostat(ThermostatDevice):
|
||||
if temp is None:
|
||||
return super().min_temp
|
||||
else:
|
||||
return round(self.hass.config.temperature(temp, TEMP_CELCIUS)[0])
|
||||
return temp
|
||||
|
||||
@property
|
||||
def max_temp(self):
|
||||
@ -136,7 +133,7 @@ class NestThermostat(ThermostatDevice):
|
||||
if temp is None:
|
||||
return super().max_temp
|
||||
else:
|
||||
return round(self.hass.config.temperature(temp, TEMP_CELCIUS)[0])
|
||||
return temp
|
||||
|
||||
def update(self):
|
||||
""" Python-nest has its own mechanism for staying up to date. """
|
||||
|
Loading…
x
Reference in New Issue
Block a user