Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Climate component: add supported_features #10658

Merged
merged 15 commits into from
Nov 29, 2017
Merged
18 changes: 18 additions & 0 deletions homeassistant/components/climate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@
STATE_HEAT_PUMP = 'heat_pump'
STATE_GAS = 'gas'

SUPPORT_TARGET_TEMPERATURE = 1
SUPPORT_TARGET_TEMPERATURE_HIGH = 2
SUPPORT_TARGET_TEMPERATURE_LOW = 4
SUPPORT_TARGET_HUMIDITY = 8
SUPPORT_TARGET_HUMIDITY_HIGH = 16
SUPPORT_TARGET_HUMIDITY_LOW = 32
SUPPORT_FAN_MODE = 64
SUPPORT_OPERATION_MODE = 128
SUPPORT_HOLD_MODE = 256
SUPPORT_SWING_MODE = 512
SUPPORT_AWAY_MODE = 1024
SUPPORT_AUX_HEAT = 2048

ATTR_CURRENT_TEMPERATURE = 'current_temperature'
ATTR_MAX_TEMP = 'max_temp'
ATTR_MIN_TEMP = 'min_temp'
Expand Down Expand Up @@ -717,6 +730,11 @@ def async_turn_aux_heat_off(self):
"""
return self.hass.async_add_job(self.turn_aux_heat_off)

@property
def supported_features(self):
"""Return the list of supported features."""
raise NotImplementedError()

@property
def min_temp(self):
"""Return the minimum temperature."""
Expand Down
17 changes: 16 additions & 1 deletion homeassistant/components/climate/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@
https://home-assistant.io/components/demo/
"""
from homeassistant.components.climate import (
ClimateDevice, ATTR_TARGET_TEMP_HIGH, ATTR_TARGET_TEMP_LOW)
ClimateDevice, ATTR_TARGET_TEMP_HIGH, ATTR_TARGET_TEMP_LOW,
SUPPORT_TARGET_TEMPERATURE, SUPPORT_TARGET_HUMIDITY,
SUPPORT_AWAY_MODE, SUPPORT_HOLD_MODE, SUPPORT_FAN_MODE,
SUPPORT_OPERATION_MODE, SUPPORT_AUX_HEAT, SUPPORT_SWING_MODE,
SUPPORT_TARGET_TEMPERATURE_HIGH, SUPPORT_TARGET_TEMPERATURE_LOW)
from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT, ATTR_TEMPERATURE

SUPPORT_FLAGS = (SUPPORT_TARGET_TEMPERATURE | SUPPORT_TARGET_HUMIDITY |
SUPPORT_AWAY_MODE | SUPPORT_HOLD_MODE | SUPPORT_FAN_MODE |
SUPPORT_OPERATION_MODE | SUPPORT_AUX_HEAT |
SUPPORT_SWING_MODE | SUPPORT_TARGET_TEMPERATURE_HIGH |
SUPPORT_TARGET_TEMPERATURE_LOW)


def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the Demo climate devices."""
Expand Down Expand Up @@ -47,6 +57,11 @@ def __init__(self, name, target_temperature, unit_of_measurement,
self._target_temperature_high = target_temp_high
self._target_temperature_low = target_temp_low

@property
def supported_features(self):
"""Return the list of supported features."""
return SUPPORT_FLAGS

@property
def should_poll(self):
"""Return the polling state."""
Expand Down
34 changes: 29 additions & 5 deletions homeassistant/components/climate/ecobee.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
from homeassistant.components import ecobee
from homeassistant.components.climate import (
DOMAIN, STATE_COOL, STATE_HEAT, STATE_AUTO, STATE_IDLE, ClimateDevice,
ATTR_TARGET_TEMP_LOW, ATTR_TARGET_TEMP_HIGH)
ATTR_TARGET_TEMP_LOW, ATTR_TARGET_TEMP_HIGH, SUPPORT_TARGET_TEMPERATURE,
SUPPORT_AWAY_MODE, SUPPORT_HOLD_MODE, SUPPORT_OPERATION_MODE,
SUPPORT_TARGET_HUMIDITY_LOW, SUPPORT_TARGET_HUMIDITY_HIGH)
from homeassistant.const import (
ATTR_ENTITY_ID, STATE_OFF, STATE_ON, ATTR_TEMPERATURE, TEMP_FAHRENHEIT)
from homeassistant.config import load_yaml_config_file
Expand Down Expand Up @@ -44,6 +46,10 @@
vol.Optional(ATTR_RESUME_ALL, default=DEFAULT_RESUME_ALL): cv.boolean,
})

SUPPORT_FLAGS = (SUPPORT_TARGET_TEMPERATURE | SUPPORT_AWAY_MODE |
SUPPORT_HOLD_MODE | SUPPORT_OPERATION_MODE |
SUPPORT_TARGET_HUMIDITY_LOW | SUPPORT_TARGET_HUMIDITY_HIGH)


def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the Ecobee Thermostat Platform."""
Expand Down Expand Up @@ -132,6 +138,11 @@ def update(self):
self.thermostat = self.data.ecobee.get_thermostat(
self.thermostat_index)

@property
def supported_features(self):
"""Return the list of supported features."""
return SUPPORT_FLAGS

@property
def name(self):
"""Return the name of the Ecobee Thermostat."""
Expand Down Expand Up @@ -318,8 +329,21 @@ def set_hold_mode(self, hold_mode):

def set_auto_temp_hold(self, heat_temp, cool_temp):
"""Set temperature hold in auto mode."""
self.data.ecobee.set_hold_temp(self.thermostat_index, cool_temp,
heat_temp, self.hold_preference())
if cool_temp is not None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these changes to ecobee included in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because ecobee could so far only set target_temperature_high and target_temperature_low at the same time. I figured that if SUPPORT_TARGET_TEMPERATURE_HIGH and SUPPORT_TARGET_TEMPERATURE_LOW are two different flags, then it must be possible to set only one of them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the high/low target temps still be visible in the frontend graph without those supported features?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly: I can't figure out how this would currently be shown in the front end. There is code computing whether it should be shown or not in line

https://github.com/tinloaf/home-assistant-polymer/blob/8201dd34761dbb8feb219e9c9c3cb58e841dd412/src/more-infos/more-info-climate.html#L272

(still based on the old attribute-based detection), but that is never used. The actual temperature controls in

https://github.com/tinloaf/home-assistant-polymer/blob/8201dd34761dbb8feb219e9c9c3cb58e841dd412/src/more-infos/more-info-climate.html#L95-L108

also don't use it. The included ha-climate-control also doesn't seem to support it.

In short: I did not change anything regarding low / high temperatures, I just added the support flag. It does not seem that the front end currently supports setting these values. It would be a next step to implement that in the front end.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We used to have a slider with 2 handles to set low and high temp. It got removed in favor of the big buttons and then we lost that functionality.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which functionality is lost?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is currently no way of setting target_temperature_high or target_temperature_low via the front end. You can of course still set it via service calls.

cool_temp_setpoint = cool_temp
else:
cool_temp_setpoint = (
self.thermostat['runtime']['desiredCool'] / 10.0)

if heat_temp is not None:
heat_temp_setpoint = heat_temp
else:
heat_temp_setpoint = (
self.thermostat['runtime']['desiredCool'] / 10.0)

self.data.ecobee.set_hold_temp(self.thermostat_index,
cool_temp_setpoint, heat_temp_setpoint,
self.hold_preference())
_LOGGER.debug("Setting ecobee hold_temp to: heat=%s, is=%s, "
"cool=%s, is=%s", heat_temp, isinstance(
heat_temp, (int, float)), cool_temp,
Expand Down Expand Up @@ -348,8 +372,8 @@ def set_temperature(self, **kwargs):
high_temp = kwargs.get(ATTR_TARGET_TEMP_HIGH)
temp = kwargs.get(ATTR_TEMPERATURE)

if self.current_operation == STATE_AUTO and low_temp is not None \
and high_temp is not None:
if self.current_operation == STATE_AUTO and (low_temp is not None or
high_temp is not None):
self.set_auto_temp_hold(low_temp, high_temp)
elif temp is not None:
self.set_temp_hold(temp)
Expand Down
7 changes: 6 additions & 1 deletion homeassistant/components/climate/ephember.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import voluptuous as vol

from homeassistant.components.climate import (
ClimateDevice, PLATFORM_SCHEMA, STATE_HEAT, STATE_IDLE)
ClimateDevice, PLATFORM_SCHEMA, STATE_HEAT, STATE_IDLE, SUPPORT_AUX_HEAT)
from homeassistant.const import (
TEMP_CELSIUS, CONF_USERNAME, CONF_PASSWORD)
import homeassistant.helpers.config_validation as cv
Expand Down Expand Up @@ -56,6 +56,11 @@ def __init__(self, ember, zone):
self._zone = zone
self._hot_water = zone['isHotWater']

@property
def supported_features(self):
"""Return the list of supported features."""
return SUPPORT_AUX_HEAT

@property
def name(self):
"""Return the name of the thermostat, if any."""
Expand Down
11 changes: 10 additions & 1 deletion homeassistant/components/climate/eq3btsmart.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import voluptuous as vol

from homeassistant.components.climate import (
STATE_ON, STATE_OFF, STATE_AUTO, PLATFORM_SCHEMA, ClimateDevice)
STATE_ON, STATE_OFF, STATE_AUTO, PLATFORM_SCHEMA, ClimateDevice,
SUPPORT_TARGET_TEMPERATURE, SUPPORT_OPERATION_MODE, SUPPORT_AWAY_MODE)
from homeassistant.const import (
CONF_MAC, CONF_DEVICES, TEMP_CELSIUS, ATTR_TEMPERATURE, PRECISION_HALVES)
import homeassistant.helpers.config_validation as cv
Expand Down Expand Up @@ -37,6 +38,9 @@
vol.Schema({cv.string: DEVICE_SCHEMA}),
})

SUPPORT_FLAGS = (SUPPORT_TARGET_TEMPERATURE | SUPPORT_OPERATION_MODE |
SUPPORT_AWAY_MODE)


def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the eQ-3 BLE thermostats."""
Expand Down Expand Up @@ -72,6 +76,11 @@ def __init__(self, _mac, _name):
self._name = _name
self._thermostat = eq3.Thermostat(_mac)

@property
def supported_features(self):
"""Return the list of supported features."""
return SUPPORT_FLAGS

@property
def available(self) -> bool:
"""Return if thermostat is available."""
Expand Down
11 changes: 10 additions & 1 deletion homeassistant/components/climate/flexit.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
from homeassistant.const import (
CONF_NAME, CONF_SLAVE, TEMP_CELSIUS,
ATTR_TEMPERATURE, DEVICE_DEFAULT_NAME)
from homeassistant.components.climate import (ClimateDevice, PLATFORM_SCHEMA)
from homeassistant.components.climate import (
ClimateDevice, PLATFORM_SCHEMA, SUPPORT_TARGET_TEMPERATURE,
SUPPORT_FAN_MODE)
import homeassistant.components.modbus as modbus
import homeassistant.helpers.config_validation as cv

Expand All @@ -31,6 +33,8 @@

_LOGGER = logging.getLogger(__name__)

SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE


def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the Flexit Platform."""
Expand Down Expand Up @@ -62,6 +66,11 @@ def __init__(self, modbus_slave, name):
self._alarm = False
self.unit = pyflexit.pyflexit(modbus.HUB, modbus_slave)

@property
def supported_features(self):
"""Return the list of supported features."""
return SUPPORT_FLAGS

def update(self):
"""Update unit attributes."""
if not self.unit.update():
Expand Down
8 changes: 7 additions & 1 deletion homeassistant/components/climate/generic_thermostat.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from homeassistant.core import DOMAIN as HA_DOMAIN
from homeassistant.components.climate import (
STATE_HEAT, STATE_COOL, STATE_IDLE, ClimateDevice, PLATFORM_SCHEMA,
STATE_AUTO)
STATE_AUTO, SUPPORT_OPERATION_MODE, SUPPORT_TARGET_TEMPERATURE)
from homeassistant.const import (
ATTR_UNIT_OF_MEASUREMENT, STATE_ON, STATE_OFF, ATTR_TEMPERATURE,
CONF_NAME, ATTR_ENTITY_ID, SERVICE_TURN_ON, SERVICE_TURN_OFF)
Expand Down Expand Up @@ -41,6 +41,7 @@
CONF_HOT_TOLERANCE = 'hot_tolerance'
CONF_KEEP_ALIVE = 'keep_alive'

SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_OPERATION_MODE

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_HEATER): cv.entity_id,
Expand Down Expand Up @@ -313,6 +314,11 @@ def _is_device_active(self):
"""If the toggleable device is currently active."""
return self.hass.states.is_state(self.heater_entity_id, STATE_ON)

@property
def supported_features(self):
"""Return the list of supported features."""
return SUPPORT_FLAGS

@callback
def _heater_turn_on(self):
"""Turn heater toggleable device on."""
Expand Down
8 changes: 7 additions & 1 deletion homeassistant/components/climate/heatmiser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

import voluptuous as vol

from homeassistant.components.climate import ClimateDevice, PLATFORM_SCHEMA
from homeassistant.components.climate import (
ClimateDevice, PLATFORM_SCHEMA, SUPPORT_TARGET_TEMPERATURE)
from homeassistant.const import (
TEMP_CELSIUS, ATTR_TEMPERATURE, CONF_PORT, CONF_NAME, CONF_ID)
import homeassistant.helpers.config_validation as cv
Expand Down Expand Up @@ -68,6 +69,11 @@ def __init__(self, heatmiser, device, name, serport):
self.update()
self._target_temperature = int(self.dcb.get('roomset'))

@property
def supported_features(self):
"""Return the list of supported features."""
return SUPPORT_TARGET_TEMPERATURE

@property
def name(self):
"""Return the name of the thermostat, if any."""
Expand Down
13 changes: 10 additions & 3 deletions homeassistant/components/climate/hive.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/climate.hive/
"""
from homeassistant.components.climate import (ClimateDevice,
STATE_AUTO, STATE_HEAT,
STATE_OFF, STATE_ON)
from homeassistant.components.climate import (
ClimateDevice, STATE_AUTO, STATE_HEAT, STATE_OFF, STATE_ON,
SUPPORT_TARGET_TEMPERATURE, SUPPORT_OPERATION_MODE)
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
from homeassistant.components.hive import DATA_HIVE

Expand All @@ -16,6 +16,8 @@
HASS_TO_HIVE_STATE = {STATE_AUTO: 'SCHEDULE', STATE_HEAT: 'MANUAL',
STATE_ON: 'ON', STATE_OFF: 'OFF'}

SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_OPERATION_MODE


def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up Hive climate devices."""
Expand Down Expand Up @@ -45,6 +47,11 @@ def __init__(self, hivesession, hivedevice):

self.session.entities.append(self)

@property
def supported_features(self):
"""Return the list of supported features."""
return SUPPORT_FLAGS

def handle_update(self, updatesource):
"""Handle the new update request."""
if '{}.{}'.format(self.device_type, self.node_id) not in updatesource:
Expand Down
11 changes: 10 additions & 1 deletion homeassistant/components/climate/homematic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
https://home-assistant.io/components/climate.homematic/
"""
import logging
from homeassistant.components.climate import ClimateDevice, STATE_AUTO
from homeassistant.components.climate import (
ClimateDevice, STATE_AUTO, SUPPORT_TARGET_TEMPERATURE,
SUPPORT_OPERATION_MODE)
from homeassistant.components.homematic import HMDevice, ATTR_DISCOVER_DEVICES
from homeassistant.const import TEMP_CELSIUS, STATE_UNKNOWN, ATTR_TEMPERATURE

Expand Down Expand Up @@ -38,6 +40,8 @@

HM_CONTROL_MODE = 'CONTROL_MODE'

SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_OPERATION_MODE


def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the Homematic thermostat platform."""
Expand All @@ -55,6 +59,11 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class HMThermostat(HMDevice, ClimateDevice):
"""Representation of a Homematic thermostat."""

@property
def supported_features(self):
"""Return the list of supported features."""
return SUPPORT_FLAGS

@property
def temperature_unit(self):
"""Return the unit of measurement that is used."""
Expand Down
19 changes: 18 additions & 1 deletion homeassistant/components/climate/honeywell.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
import homeassistant.helpers.config_validation as cv
from homeassistant.components.climate import (
ClimateDevice, PLATFORM_SCHEMA, ATTR_FAN_MODE, ATTR_FAN_LIST,
ATTR_OPERATION_MODE, ATTR_OPERATION_LIST)
ATTR_OPERATION_MODE, ATTR_OPERATION_LIST, SUPPORT_TARGET_TEMPERATURE,
SUPPORT_AWAY_MODE, SUPPORT_OPERATION_MODE)
from homeassistant.const import (
CONF_PASSWORD, CONF_USERNAME, TEMP_CELSIUS, TEMP_FAHRENHEIT,
ATTR_TEMPERATURE, CONF_REGION)
Expand Down Expand Up @@ -126,6 +127,14 @@ def __init__(self, client, zone_id, master, away_temp):
self._away_temp = away_temp
self._away = False

@property
def supported_features(self):
"""Return the list of supported features."""
supported = (SUPPORT_TARGET_TEMPERATURE | SUPPORT_AWAY_MODE)
if hasattr(self.client, ATTR_SYSTEM_MODE):
supported |= SUPPORT_OPERATION_MODE
return supported

@property
def name(self):
"""Return the name of the honeywell, if any."""
Expand Down Expand Up @@ -234,6 +243,14 @@ def __init__(self, client, device, cool_away_temp,
self._username = username
self._password = password

@property
def supported_features(self):
"""Return the list of supported features."""
supported = (SUPPORT_TARGET_TEMPERATURE | SUPPORT_AWAY_MODE)
if hasattr(self._device, ATTR_SYSTEM_MODE):
supported |= SUPPORT_OPERATION_MODE
return supported

@property
def is_fan_on(self):
"""Return true if fan is on."""
Expand Down
Loading