add fan_min_on_time service to ecobee (#2159)

This commit is contained in:
Thiago Oliveira 2016-06-09 23:34:29 -07:00 committed by Paulus Schoutsen
parent 213a738240
commit 02f342b670
5 changed files with 72 additions and 7 deletions

View File

@ -22,7 +22,7 @@ HOLD_TEMP = 'hold_temp'
REQUIREMENTS = [ REQUIREMENTS = [
'https://github.com/nkgilley/python-ecobee-api/archive/' 'https://github.com/nkgilley/python-ecobee-api/archive/'
'4a884bc146a93991b4210f868f3d6aecf0a181e6.zip#python-ecobee==0.0.5'] '4856a704670c53afe1882178a89c209b5f98533d.zip#python-ecobee==0.0.6']
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)

View File

@ -5,17 +5,29 @@ For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/thermostat.ecobee/ https://home-assistant.io/components/thermostat.ecobee/
""" """
import logging import logging
from os import path
import voluptuous as vol
from homeassistant.components import ecobee from homeassistant.components import ecobee
from homeassistant.components.thermostat import ( from homeassistant.components.thermostat import (
STATE_COOL, STATE_HEAT, STATE_IDLE, ThermostatDevice) DOMAIN, STATE_COOL, STATE_HEAT, STATE_IDLE, ThermostatDevice)
from homeassistant.const import STATE_OFF, STATE_ON, TEMP_FAHRENHEIT from homeassistant.const import (
ATTR_ENTITY_ID, STATE_OFF, STATE_ON, TEMP_FAHRENHEIT)
from homeassistant.config import load_yaml_config_file
import homeassistant.helpers.config_validation as cv
DEPENDENCIES = ['ecobee'] DEPENDENCIES = ['ecobee']
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
ECOBEE_CONFIG_FILE = 'ecobee.conf' ECOBEE_CONFIG_FILE = 'ecobee.conf'
_CONFIGURING = {} _CONFIGURING = {}
ATTR_FAN_MIN_ON_TIME = "fan_min_on_time"
SERVICE_SET_FAN_MIN_ON_TIME = "ecobee_set_fan_min_on_time"
SET_FAN_MIN_ON_TIME_SCHEMA = vol.Schema({
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
vol.Required(ATTR_FAN_MIN_ON_TIME): vol.Coerce(int),
})
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Ecobee Thermostat Platform.""" """Setup the Ecobee Thermostat Platform."""
@ -26,10 +38,37 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
_LOGGER.info( _LOGGER.info(
"Loading ecobee thermostat component with hold_temp set to %s", "Loading ecobee thermostat component with hold_temp set to %s",
hold_temp) hold_temp)
add_devices(Thermostat(data, index, hold_temp) devices = [Thermostat(data, index, hold_temp)
for index in range(len(data.ecobee.thermostats))) for index in range(len(data.ecobee.thermostats))]
add_devices(devices)
def fan_min_on_time_set_service(service):
"""Set the minimum fan on time on the target thermostats."""
entity_id = service.data.get('entity_id')
if entity_id:
target_thermostats = [device for device in devices
if device.entity_id == entity_id]
else:
target_thermostats = devices
fan_min_on_time = service.data[ATTR_FAN_MIN_ON_TIME]
for thermostat in target_thermostats:
thermostat.set_fan_min_on_time(str(fan_min_on_time))
thermostat.update_ha_state(True)
descriptions = load_yaml_config_file(
path.join(path.dirname(__file__), 'services.yaml'))
hass.services.register(
DOMAIN, SERVICE_SET_FAN_MIN_ON_TIME, fan_min_on_time_set_service,
descriptions.get(SERVICE_SET_FAN_MIN_ON_TIME),
schema=SET_FAN_MIN_ON_TIME_SCHEMA)
# pylint: disable=too-many-public-methods
class Thermostat(ThermostatDevice): class Thermostat(ThermostatDevice):
"""A thermostat class for Ecobee.""" """A thermostat class for Ecobee."""
@ -127,6 +166,11 @@ class Thermostat(ThermostatDevice):
"""Return current hvac mode ie. auto, auxHeatOnly, cool, heat, off.""" """Return current hvac mode ie. auto, auxHeatOnly, cool, heat, off."""
return self.thermostat['settings']['hvacMode'] return self.thermostat['settings']['hvacMode']
@property
def fan_min_on_time(self):
"""Return current fan minimum on time."""
return self.thermostat['settings']['fanMinOnTime']
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return device specific state attributes.""" """Return device specific state attributes."""
@ -135,7 +179,8 @@ class Thermostat(ThermostatDevice):
"humidity": self.humidity, "humidity": self.humidity,
"fan": self.fan, "fan": self.fan,
"mode": self.mode, "mode": self.mode,
"hvac_mode": self.hvac_mode "hvac_mode": self.hvac_mode,
"fan_min_on_time": self.fan_min_on_time
} }
@property @property
@ -177,6 +222,11 @@ class Thermostat(ThermostatDevice):
"""Set HVAC mode (auto, auxHeatOnly, cool, heat, off).""" """Set HVAC mode (auto, auxHeatOnly, cool, heat, off)."""
self.data.ecobee.set_hvac_mode(self.thermostat_index, mode) self.data.ecobee.set_hvac_mode(self.thermostat_index, mode)
def set_fan_min_on_time(self, fan_min_on_time):
"""Set the minimum fan on time."""
self.data.ecobee.set_fan_min_on_time(self.thermostat_index,
fan_min_on_time)
# Home and Sleep mode aren't used in UI yet: # Home and Sleep mode aren't used in UI yet:
# def turn_home_mode_on(self): # def turn_home_mode_on(self):

View File

@ -34,3 +34,15 @@ set_fan_mode:
fan: fan:
description: New value of fan mode description: New value of fan mode
example: true example: true
ecobee_set_fan_min_on_time:
description: Set the minimum time, in minutes, to run the fan each hour
fields:
entity_id:
descriptions: Name(s) of entities to change
example: 'thermostat.ecobee'
fan_min_on_time:
description: New value of fan minimum on time
example: 5

View File

@ -15,6 +15,8 @@ from homeassistant.components.sun import (
from homeassistant.components.thermostat import ( from homeassistant.components.thermostat import (
ATTR_AWAY_MODE, ATTR_FAN, SERVICE_SET_AWAY_MODE, SERVICE_SET_FAN_MODE, ATTR_AWAY_MODE, ATTR_FAN, SERVICE_SET_AWAY_MODE, SERVICE_SET_FAN_MODE,
SERVICE_SET_TEMPERATURE) SERVICE_SET_TEMPERATURE)
from homeassistant.components.thermostat.ecobee import (
ATTR_FAN_MIN_ON_TIME, SERVICE_SET_FAN_MIN_ON_TIME)
from homeassistant.components.hvac import ( from homeassistant.components.hvac import (
ATTR_HUMIDITY, ATTR_SWING_MODE, ATTR_OPERATION_MODE, ATTR_AUX_HEAT, ATTR_HUMIDITY, ATTR_SWING_MODE, ATTR_OPERATION_MODE, ATTR_AUX_HEAT,
SERVICE_SET_HUMIDITY, SERVICE_SET_SWING_MODE, SERVICE_SET_HUMIDITY, SERVICE_SET_SWING_MODE,
@ -46,6 +48,7 @@ SERVICE_ATTRIBUTES = {
SERVICE_NOTIFY: [ATTR_MESSAGE], SERVICE_NOTIFY: [ATTR_MESSAGE],
SERVICE_SET_AWAY_MODE: [ATTR_AWAY_MODE], SERVICE_SET_AWAY_MODE: [ATTR_AWAY_MODE],
SERVICE_SET_FAN_MODE: [ATTR_FAN], SERVICE_SET_FAN_MODE: [ATTR_FAN],
SERVICE_SET_FAN_MIN_ON_TIME: [ATTR_FAN_MIN_ON_TIME],
SERVICE_SET_TEMPERATURE: [ATTR_TEMPERATURE], SERVICE_SET_TEMPERATURE: [ATTR_TEMPERATURE],
SERVICE_SET_HUMIDITY: [ATTR_HUMIDITY], SERVICE_SET_HUMIDITY: [ATTR_HUMIDITY],
SERVICE_SET_SWING_MODE: [ATTR_SWING_MODE], SERVICE_SET_SWING_MODE: [ATTR_SWING_MODE],

View File

@ -130,7 +130,7 @@ https://github.com/jamespcole/home-assistant-nzb-clients/archive/616cad591540925
https://github.com/kellerza/pyqwikswitch/archive/v0.4.zip#pyqwikswitch==0.4 https://github.com/kellerza/pyqwikswitch/archive/v0.4.zip#pyqwikswitch==0.4
# homeassistant.components.ecobee # homeassistant.components.ecobee
https://github.com/nkgilley/python-ecobee-api/archive/4a884bc146a93991b4210f868f3d6aecf0a181e6.zip#python-ecobee==0.0.5 https://github.com/nkgilley/python-ecobee-api/archive/4856a704670c53afe1882178a89c209b5f98533d.zip#python-ecobee==0.0.6
# homeassistant.components.switch.edimax # homeassistant.components.switch.edimax
https://github.com/rkabadi/pyedimax/archive/365301ce3ff26129a7910c501ead09ea625f3700.zip#pyedimax==0.1 https://github.com/rkabadi/pyedimax/archive/365301ce3ff26129a7910c501ead09ea625f3700.zip#pyedimax==0.1