mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Initial code for generic thermostat range support and nest compliance
This commit is contained in:
parent
53b43dc4db
commit
2d54fdd979
@ -27,6 +27,9 @@ ATTR_CURRENT_TEMPERATURE = "current_temperature"
|
|||||||
ATTR_AWAY_MODE = "away_mode"
|
ATTR_AWAY_MODE = "away_mode"
|
||||||
ATTR_MAX_TEMP = "max_temp"
|
ATTR_MAX_TEMP = "max_temp"
|
||||||
ATTR_MIN_TEMP = "min_temp"
|
ATTR_MIN_TEMP = "min_temp"
|
||||||
|
ATTR_TEMPERATURE_LOW = "target_temp_low"
|
||||||
|
ATTR_TEMPERATURE_HIGH = "target_temp_high"
|
||||||
|
ATTR_OPERATION = "current_operation"
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -111,7 +114,7 @@ class ThermostatDevice(Entity):
|
|||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
""" Returns the current state. """
|
""" Returns the current state. """
|
||||||
return self.target_temperature
|
return self.operation
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
@ -134,7 +137,20 @@ class ThermostatDevice(Entity):
|
|||||||
user_unit), 0),
|
user_unit), 0),
|
||||||
ATTR_MAX_TEMP: round(convert(self.max_temp,
|
ATTR_MAX_TEMP: round(convert(self.max_temp,
|
||||||
thermostat_unit,
|
thermostat_unit,
|
||||||
user_unit), 0)
|
user_unit), 0),
|
||||||
|
ATTR_TEMPERATURE: round(convert(self.target_temperature,
|
||||||
|
thermostat_unit,
|
||||||
|
user_unit), 0),
|
||||||
|
ATTR_TEMPERATURE_LOW: round(convert(self.target_temperature_low,
|
||||||
|
thermostat_unit,
|
||||||
|
user_unit), 0),
|
||||||
|
ATTR_TEMPERATURE_HIGH: round(convert(self.target_temperature_high,
|
||||||
|
thermostat_unit,
|
||||||
|
user_unit), 0),
|
||||||
|
ATTR_OPERATION: round(convert(self.operation,
|
||||||
|
thermostat_unit,
|
||||||
|
user_unit), 0)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
is_away = self.is_away_mode_on
|
is_away = self.is_away_mode_on
|
||||||
@ -159,11 +175,26 @@ class ThermostatDevice(Entity):
|
|||||||
""" Returns the current temperature. """
|
""" Returns the current temperature. """
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@property
|
||||||
|
def operation(self):
|
||||||
|
""" Returns current operation ie. heat, cool, idle """
|
||||||
|
return NotImplementedError
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def target_temperature(self):
|
def target_temperature(self):
|
||||||
""" Returns the temperature we try to reach. """
|
""" Returns the temperature we try to reach. """
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@property
|
||||||
|
def target_temperature_low(self):
|
||||||
|
""" Returns the lower bound temperature we try to reach. """
|
||||||
|
return self.target_temperature
|
||||||
|
|
||||||
|
@property
|
||||||
|
def target_temperature_high(self):
|
||||||
|
""" Returns the upper bound temperature we try to reach. """
|
||||||
|
return self.target_temperature
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_away_mode_on(self):
|
def is_away_mode_on(self):
|
||||||
"""
|
"""
|
||||||
|
@ -8,6 +8,10 @@ import logging
|
|||||||
from homeassistant.components.thermostat import ThermostatDevice
|
from homeassistant.components.thermostat import ThermostatDevice
|
||||||
from homeassistant.const import (CONF_USERNAME, CONF_PASSWORD, TEMP_CELCIUS)
|
from homeassistant.const import (CONF_USERNAME, CONF_PASSWORD, TEMP_CELCIUS)
|
||||||
|
|
||||||
|
STATE_HEAT = "heat"
|
||||||
|
STATE_COOL = "cool"
|
||||||
|
STATE_IDLE = "idle"
|
||||||
|
|
||||||
REQUIREMENTS = ['python-nest==2.6.0']
|
REQUIREMENTS = ['python-nest==2.6.0']
|
||||||
|
|
||||||
|
|
||||||
@ -83,25 +87,52 @@ class NestThermostat(ThermostatDevice):
|
|||||||
""" Returns the current temperature. """
|
""" Returns the current temperature. """
|
||||||
return round(self.device.temperature, 1)
|
return round(self.device.temperature, 1)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def operation(self):
|
||||||
|
""" Returns current operation ie. heat, cool, idle """
|
||||||
|
if self.device.hvac_ac_state is True:
|
||||||
|
return STATE_COOL
|
||||||
|
elif self.device.hvac_heater_state is True:
|
||||||
|
return STATE_HEAT
|
||||||
|
else:
|
||||||
|
return STATE_IDLE
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def target_temperature(self):
|
def target_temperature(self):
|
||||||
""" Returns the temperature we try to reach. """
|
""" Returns the temperature we try to reach. """
|
||||||
target = self.device.target
|
target = self.device.target
|
||||||
|
|
||||||
if isinstance(target, tuple):
|
if self.device.mode == 'range':
|
||||||
low, high = target
|
low, high = target
|
||||||
|
if self.operation == STATE_COOL:
|
||||||
if self.current_temperature < low:
|
|
||||||
temp = low
|
|
||||||
elif self.current_temperature > high:
|
|
||||||
temp = high
|
temp = high
|
||||||
|
elif self.operation == STATE_HEAT:
|
||||||
|
temp = low
|
||||||
else:
|
else:
|
||||||
temp = (low + high)/2
|
range_average = (low + high)/2
|
||||||
|
if self.current_temperature < range_average:
|
||||||
|
temp = low
|
||||||
|
elif self.current_temperature > range_average:
|
||||||
|
temp = high
|
||||||
else:
|
else:
|
||||||
temp = target
|
temp = target
|
||||||
|
|
||||||
return round(temp, 1)
|
return round(temp, 1)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def target_temperature_low(self):
|
||||||
|
""" Returns the lower bound temperature we try to reach. """
|
||||||
|
if self.device.mode == 'range':
|
||||||
|
return self.device.target["low"]
|
||||||
|
return round(self.target_temperature, 1)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def target_temperature_high(self):
|
||||||
|
""" Returns the upper bound temperature we try to reach. """
|
||||||
|
if self.device.mode == 'range':
|
||||||
|
return self.device.target["high"]
|
||||||
|
return round(self.target_temperature, 1)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_away_mode_on(self):
|
def is_away_mode_on(self):
|
||||||
""" Returns if away mode is on. """
|
""" Returns if away mode is on. """
|
||||||
@ -109,6 +140,11 @@ class NestThermostat(ThermostatDevice):
|
|||||||
|
|
||||||
def set_temperature(self, temperature):
|
def set_temperature(self, temperature):
|
||||||
""" Set new target temperature """
|
""" Set new target temperature """
|
||||||
|
if self.device.mode == 'range':
|
||||||
|
if self.target_temperature == self.target_temperature_low:
|
||||||
|
temperature = (temperature, self.target_temperature_high)
|
||||||
|
elif self.target_temperature == self.target_temperature_high:
|
||||||
|
temperature = (self.target_temperature_low, temperature)
|
||||||
self.device.target = temperature
|
self.device.target = temperature
|
||||||
|
|
||||||
def turn_away_mode_on(self):
|
def turn_away_mode_on(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user