Skip to content

Commit

Permalink
Added stuff for support range setting (home-assistant#3189)
Browse files Browse the repository at this point in the history
  • Loading branch information
turbokongen authored and Teagan42 committed Sep 9, 2016
1 parent 5453291 commit ba28208
Show file tree
Hide file tree
Showing 15 changed files with 231 additions and 96 deletions.
61 changes: 37 additions & 24 deletions homeassistant/components/climate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from homeassistant.helpers.entity_component import EntityComponent

from homeassistant.config import load_yaml_config_file
import homeassistant.util as util
from homeassistant.util.temperature import convert as convert_temperature
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
Expand Down Expand Up @@ -44,6 +43,8 @@
ATTR_CURRENT_TEMPERATURE = "current_temperature"
ATTR_MAX_TEMP = "max_temp"
ATTR_MIN_TEMP = "min_temp"
ATTR_TARGET_TEMP_HIGH = "target_temp_high"
ATTR_TARGET_TEMP_LOW = "target_temp_low"
ATTR_AWAY_MODE = "away_mode"
ATTR_AUX_HEAT = "aux_heat"
ATTR_FAN_MODE = "fan_mode"
Expand All @@ -68,8 +69,10 @@
vol.Required(ATTR_AUX_HEAT): cv.boolean,
})
SET_TEMPERATURE_SCHEMA = vol.Schema({
vol.Exclusive(ATTR_TEMPERATURE, 'temperature'): vol.Coerce(float),
vol.Inclusive(ATTR_TARGET_TEMP_HIGH, 'temperature'): vol.Coerce(float),
vol.Inclusive(ATTR_TARGET_TEMP_LOW, 'temperature'): vol.Coerce(float),
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
vol.Required(ATTR_TEMPERATURE): vol.Coerce(float),
})
SET_FAN_MODE_SCHEMA = vol.Schema({
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
Expand Down Expand Up @@ -113,14 +116,19 @@ def set_aux_heat(hass, aux_heat, entity_id=None):
hass.services.call(DOMAIN, SERVICE_SET_AUX_HEAT, data)


def set_temperature(hass, temperature, entity_id=None):
def set_temperature(hass, temperature=None, entity_id=None,
target_temp_high=None, target_temp_low=None):
"""Set new target temperature."""
data = {ATTR_TEMPERATURE: temperature}

if entity_id is not None:
data[ATTR_ENTITY_ID] = entity_id

hass.services.call(DOMAIN, SERVICE_SET_TEMPERATURE, data)
kwargs = {
key: value for key, value in [
(ATTR_TEMPERATURE, temperature),
(ATTR_TARGET_TEMP_HIGH, target_temp_high),
(ATTR_TARGET_TEMP_LOW, target_temp_low),
(ATTR_ENTITY_ID, entity_id),
] if value is not None
}
_LOGGER.debug("set_temperature start data=%s", kwargs)
hass.services.call(DOMAIN, SERVICE_SET_TEMPERATURE, kwargs)


def set_humidity(hass, humidity, entity_id=None):
Expand Down Expand Up @@ -227,20 +235,9 @@ def aux_heat_set_service(service):
def temperature_set_service(service):
"""Set temperature on the target climate devices."""
target_climate = component.extract_from_service(service)

temperature = util.convert(
service.data.get(ATTR_TEMPERATURE), float)

if temperature is None:
_LOGGER.error(
"Received call to %s without attribute %s",
SERVICE_SET_TEMPERATURE, ATTR_TEMPERATURE)
return

kwargs = service.data
for climate in target_climate:
climate.set_temperature(convert_temperature(
temperature, hass.config.units.temperature_unit,
climate.unit_of_measurement))
climate.set_temperature(**kwargs)

if climate.should_poll:
climate.update_ha_state(True)
Expand Down Expand Up @@ -351,7 +348,7 @@ class ClimateDevice(Entity):
@property
def state(self):
"""Return the current state."""
return self.target_temperature or STATE_UNKNOWN
return self.current_operation or STATE_UNKNOWN

@property
def state_attributes(self):
Expand All @@ -364,6 +361,12 @@ def state_attributes(self):
ATTR_TEMPERATURE:
self._convert_for_display(self.target_temperature),
}
target_temp_high = self.target_temperature_high
if target_temp_high is not None:
data[ATTR_TARGET_TEMP_HIGH] = self._convert_for_display(
self.target_temperature_high)
data[ATTR_TARGET_TEMP_LOW] = self._convert_for_display(
self.target_temperature_low)

humidity = self.target_humidity
if humidity is not None:
Expand Down Expand Up @@ -432,6 +435,16 @@ def target_temperature(self):
"""Return the temperature we try to reach."""
return None

@property
def target_temperature_high(self):
"""Return the highbound target temperature we try to reach."""
return None

@property
def target_temperature_low(self):
"""Return the lowbound target temperature we try to reach."""
return None

@property
def is_away_mode_on(self):
"""Return true if away mode is on."""
Expand Down Expand Up @@ -462,7 +475,7 @@ def swing_list(self):
"""List of available swing modes."""
return None

def set_temperature(self, temperature):
def set_temperature(self, **kwargs):
"""Set new target temperature."""
raise NotImplementedError()

Expand Down
38 changes: 29 additions & 9 deletions homeassistant/components/climate/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
For more details about this platform, please refer to the documentation
https://home-assistant.io/components/demo/
"""
from homeassistant.components.climate import ClimateDevice
from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT
from homeassistant.components.climate import (
ClimateDevice, ATTR_TARGET_TEMP_HIGH, ATTR_TARGET_TEMP_LOW)
from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT, ATTR_TEMPERATURE


def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Demo climate devices."""
add_devices([
DemoClimate("HeatPump", 68, TEMP_FAHRENHEIT, None, 77, "Auto Low",
None, None, "Auto", "Heat", None),
None, None, "Auto", "heat", None, None, None),
DemoClimate("Hvac", 21, TEMP_CELSIUS, True, 22, "On High",
67, 54, "Off", "Cool", False),
67, 54, "Off", "cool", False, None, None),
DemoClimate("Ecobee", 23, TEMP_CELSIUS, None, 23, "Auto Low",
None, None, "Auto", "auto", None, 24, 21)
])


Expand All @@ -26,7 +29,7 @@ class DemoClimate(ClimateDevice):
def __init__(self, name, target_temperature, unit_of_measurement,
away, current_temperature, current_fan_mode,
target_humidity, current_humidity, current_swing_mode,
current_operation, aux):
current_operation, aux, target_temp_high, target_temp_low):
"""Initialize the climate device."""
self._name = name
self._target_temperature = target_temperature
Expand All @@ -40,8 +43,10 @@ def __init__(self, name, target_temperature, unit_of_measurement,
self._aux = aux
self._current_swing_mode = current_swing_mode
self._fan_list = ["On Low", "On High", "Auto Low", "Auto High", "Off"]
self._operation_list = ["Heat", "Cool", "Auto Changeover", "Off"]
self._operation_list = ["heat", "cool", "auto", "off"]
self._swing_list = ["Auto", "1", "2", "3", "Off"]
self._target_temperature_high = target_temp_high
self._target_temperature_low = target_temp_low

@property
def should_poll(self):
Expand All @@ -68,6 +73,16 @@ def target_temperature(self):
"""Return the temperature we try to reach."""
return self._target_temperature

@property
def target_temperature_high(self):
"""Return the highbound target temperature we try to reach."""
return self._target_temperature_high

@property
def target_temperature_low(self):
"""Return the lowbound target temperature we try to reach."""
return self._target_temperature_low

@property
def current_humidity(self):
"""Return the current humidity."""
Expand Down Expand Up @@ -108,9 +123,14 @@ def fan_list(self):
"""List of available fan modes."""
return self._fan_list

def set_temperature(self, temperature):
"""Set new target temperature."""
self._target_temperature = temperature
def set_temperature(self, **kwargs):
"""Set new target temperatures."""
if kwargs.get(ATTR_TEMPERATURE) is not None:
self._target_temperature = kwargs.get(ATTR_TEMPERATURE)
if kwargs.get(ATTR_TARGET_TEMP_HIGH) is not None and \
kwargs.get(ATTR_TARGET_TEMP_LOW) is not None:
self._target_temperature_high = kwargs.get(ATTR_TARGET_TEMP_HIGH)
self._target_temperature_low = kwargs.get(ATTR_TARGET_TEMP_LOW)
self.update_ha_state()

def set_humidity(self, humidity):
Expand Down
25 changes: 18 additions & 7 deletions homeassistant/components/climate/ecobee.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@

from homeassistant.components import ecobee
from homeassistant.components.climate import (
DOMAIN, STATE_COOL, STATE_HEAT, STATE_IDLE, ClimateDevice)
DOMAIN, STATE_COOL, STATE_HEAT, STATE_IDLE, ClimateDevice,
ATTR_TARGET_TEMP_LOW, ATTR_TARGET_TEMP_HIGH)
from homeassistant.const import (
ATTR_ENTITY_ID, STATE_OFF, STATE_ON, TEMP_FAHRENHEIT)
ATTR_ENTITY_ID, STATE_OFF, STATE_ON, TEMP_FAHRENHEIT, ATTR_TEMPERATURE)
from homeassistant.config import load_yaml_config_file
import homeassistant.helpers.config_validation as cv

Expand Down Expand Up @@ -145,7 +146,11 @@ def fan(self):
@property
def current_operation(self):
"""Return current operation."""
return self.operation_mode
if self.operation_mode == 'auxHeatOnly' or \
self.operation_mode == 'heatPump':
return STATE_HEAT
else:
return self.operation_mode

@property
def operation_list(self):
Expand Down Expand Up @@ -214,11 +219,17 @@ def turn_away_mode_off(self):
"""Turn away off."""
self.data.ecobee.resume_program(self.thermostat_index)

def set_temperature(self, temperature):
def set_temperature(self, **kwargs):
"""Set new target temperature."""
temperature = int(temperature)
low_temp = temperature - 1
high_temp = temperature + 1
if kwargs.get(ATTR_TEMPERATURE) is not None:
temperature = kwargs.get(ATTR_TEMPERATURE)
low_temp = temperature - 1
high_temp = temperature + 1
if kwargs.get(ATTR_TARGET_TEMP_LOW) is not None and \
kwargs.get(ATTR_TARGET_TEMP_HIGH) is not None:
low_temp = kwargs.get(ATTR_TARGET_TEMP_LOW)
high_temp = kwargs.get(ATTR_TARGET_TEMP_HIGH)

if self.hold_temp:
self.data.ecobee.set_hold_temp(self.thermostat_index, low_temp,
high_temp, "indefinite")
Expand Down
7 changes: 5 additions & 2 deletions homeassistant/components/climate/eq3btsmart.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import logging

from homeassistant.components.climate import ClimateDevice
from homeassistant.const import TEMP_CELSIUS, CONF_DEVICES
from homeassistant.const import TEMP_CELSIUS, CONF_DEVICES, ATTR_TEMPERATURE
from homeassistant.util.temperature import convert

REQUIREMENTS = ['bluepy_devices==0.2.0']
Expand Down Expand Up @@ -60,8 +60,11 @@ def target_temperature(self):
"""Return the temperature we try to reach."""
return self._thermostat.target_temperature

def set_temperature(self, temperature):
def set_temperature(self, **kwargs):
"""Set new target temperature."""
temperature = kwargs.get(ATTR_TEMPERATURE)
if temperature is None:
return
self._thermostat.target_temperature = temperature

@property
Expand Down
8 changes: 6 additions & 2 deletions homeassistant/components/climate/generic_thermostat.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from homeassistant.components import switch
from homeassistant.components.climate import (
STATE_HEAT, STATE_COOL, STATE_IDLE, ClimateDevice)
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, STATE_ON, STATE_OFF
from homeassistant.const import (
ATTR_UNIT_OF_MEASUREMENT, STATE_ON, STATE_OFF, ATTR_TEMPERATURE)
from homeassistant.helpers import condition
from homeassistant.helpers.event import track_state_change

Expand Down Expand Up @@ -123,8 +124,11 @@ def target_temperature(self):
"""Return the temperature we try to reach."""
return self._target_temp

def set_temperature(self, temperature):
def set_temperature(self, **kwargs):
"""Set new target temperature."""
temperature = kwargs.get(ATTR_TEMPERATURE)
if temperature is None:
return
self._target_temp = temperature
self._control_heating()
self.update_ha_state()
Expand Down
10 changes: 6 additions & 4 deletions homeassistant/components/climate/heatmiser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import logging

from homeassistant.components.climate import ClimateDevice
from homeassistant.const import TEMP_CELSIUS
from homeassistant.const import TEMP_CELSIUS, ATTR_TEMPERATURE

CONF_IPADDRESS = 'ipaddress'
CONF_PORT = 'port'
Expand Down Expand Up @@ -98,16 +98,18 @@ def target_temperature(self):
"""Return the temperature we try to reach."""
return self._target_temperature

def set_temperature(self, temperature):
def set_temperature(self, **kwargs):
"""Set new target temperature."""
temperature = int(temperature)
temperature = kwargs.get(ATTR_TEMPERATURE)
if temperature is None:
return
self.heatmiser.hmSendAddress(
self._id,
18,
temperature,
1,
self.serport)
self._target_temperature = int(temperature)
self._target_temperature = temperature

def update(self):
"""Get the latest data."""
Expand Down
7 changes: 5 additions & 2 deletions homeassistant/components/climate/homematic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import homeassistant.components.homematic as homematic
from homeassistant.components.climate import ClimateDevice, STATE_AUTO
from homeassistant.util.temperature import convert
from homeassistant.const import TEMP_CELSIUS, STATE_UNKNOWN
from homeassistant.const import TEMP_CELSIUS, STATE_UNKNOWN, ATTR_TEMPERATURE

DEPENDENCIES = ['homematic']

Expand Down Expand Up @@ -90,10 +90,13 @@ def target_temperature(self):
return None
return self._data.get('SET_TEMPERATURE', None)

def set_temperature(self, temperature):
def set_temperature(self, **kwargs):
"""Set new target temperature."""
temperature = kwargs.get(ATTR_TEMPERATURE)
if not self.available:
return None
if temperature is None:
return
self._hmdevice.set_temperature(temperature)

def set_operation_mode(self, operation_mode):
Expand Down
13 changes: 10 additions & 3 deletions homeassistant/components/climate/honeywell.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

from homeassistant.components.climate import ClimateDevice
from homeassistant.const import (
CONF_PASSWORD, CONF_USERNAME, TEMP_CELSIUS, TEMP_FAHRENHEIT)
CONF_PASSWORD, CONF_USERNAME, TEMP_CELSIUS, TEMP_FAHRENHEIT,
ATTR_TEMPERATURE)

REQUIREMENTS = ['evohomeclient==0.2.5',
'somecomfort==0.2.1']
Expand Down Expand Up @@ -132,8 +133,11 @@ def target_temperature(self):
return None
return self._target_temperature

def set_temperature(self, temperature):
def set_temperature(self, **kwargs):
"""Set new target temperature."""
temperature = kwargs.get(ATTR_TEMPERATURE)
if temperature is None:
return
self.device.set_temperature(self._name, temperature)

@property
Expand Down Expand Up @@ -234,8 +238,11 @@ def current_operation(self: ClimateDevice) -> str:
"""Return current operation ie. heat, cool, idle."""
return getattr(self._device, 'system_mode', None)

def set_temperature(self, temperature):
def set_temperature(self, **kwargs):
"""Set target temperature."""
temperature = kwargs.get(ATTR_TEMPERATURE)
if temperature is None:
return
import somecomfort
try:
if self._device.system_mode == 'cool':
Expand Down
Loading

0 comments on commit ba28208

Please sign in to comment.