Merge pull request #695 from nkgilley/ecobee

Improve ecobee support for multiple thermostats
This commit is contained in:
Paulus Schoutsen 2015-12-03 13:25:08 -08:00
commit d0ae22428d
4 changed files with 45 additions and 28 deletions

View file

@ -44,7 +44,7 @@ HOLD_TEMP = 'hold_temp'
REQUIREMENTS = [ REQUIREMENTS = [
'https://github.com/nkgilley/python-ecobee-api/archive/' 'https://github.com/nkgilley/python-ecobee-api/archive/'
'd35596b67c75451fa47001c493a15eebee195e93.zip#python-ecobee==0.0.1'] '5645f843b64ac4f6e59dfb96233a07083c5e10c1.zip#python-ecobee==0.0.3']
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)

View file

@ -48,14 +48,16 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
""" Sets up the sensors. """ """ Sets up the sensors. """
if discovery_info is None: if discovery_info is None:
return return
data = ecobee.NETWORK
dev = list() dev = list()
for name, data in ecobee.NETWORK.ecobee.sensors.items(): for index in range(len(data.ecobee.thermostats)):
if 'temp' in data: for sensor in data.ecobee.get_remote_sensors(index):
dev.append(EcobeeSensor(name, 'temperature')) for item in sensor['capability']:
if 'humidity' in data: if item['type'] not in ('temperature',
dev.append(EcobeeSensor(name, 'humidity')) 'humidity', 'occupancy'):
if 'occupancy' in data: continue
dev.append(EcobeeSensor(name, 'occupancy'))
dev.append(EcobeeSensor(sensor['name'], item['type'], index))
add_devices(dev) add_devices(dev)
@ -63,10 +65,11 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class EcobeeSensor(Entity): class EcobeeSensor(Entity):
""" An ecobee sensor. """ """ An ecobee sensor. """
def __init__(self, sensor_name, sensor_type): def __init__(self, sensor_name, sensor_type, sensor_index):
self._name = sensor_name + ' ' + SENSOR_TYPES[sensor_type][0] self._name = sensor_name + ' ' + SENSOR_TYPES[sensor_type][0]
self.sensor_name = sensor_name self.sensor_name = sensor_name
self.type = sensor_type self.type = sensor_type
self.index = sensor_index
self._state = None self._state = None
self._unit_of_measurement = SENSOR_TYPES[sensor_type][1] self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]
self.update() self.update()
@ -85,11 +88,22 @@ class EcobeeSensor(Entity):
return self._unit_of_measurement return self._unit_of_measurement
def update(self): def update(self):
ecobee.NETWORK.update() data = ecobee.NETWORK
data = ecobee.NETWORK.ecobee.sensors[self.sensor_name] data.update()
if self.type == 'temperature': for sensor in data.ecobee.get_remote_sensors(self.index):
self._state = data['temp'] for item in sensor['capability']:
elif self.type == 'humidity': if (
self._state = data['humidity'] item['type'] == self.type and
elif self.type == 'occupancy': self.type == 'temperature' and
self._state = data['occupancy'] self.sensor_name == sensor['name']):
self._state = float(item['value']) / 10
elif (
item['type'] == self.type and
self.type == 'humidity' and
self.sensor_name == sensor['name']):
self._state = item['value']
elif (
item['type'] == self.type and
self.type == 'occupancy' and
self.sensor_name == sensor['name']):
self._state = item['value']

View file

@ -164,14 +164,15 @@ class Thermostat(ThermostatDevice):
""" Turns away on. """ """ Turns away on. """
self._away = True self._away = True
if self.hold_temp: if self.hold_temp:
self.data.ecobee.set_climate_hold("away", "indefinite") self.data.ecobee.set_climate_hold(self.thermostat_index,
"away", "indefinite")
else: else:
self.data.ecobee.set_climate_hold("away") self.data.ecobee.set_climate_hold(self.thermostat_index, "away")
def turn_away_mode_off(self): def turn_away_mode_off(self):
""" Turns away off. """ """ Turns away off. """
self._away = False self._away = False
self.data.ecobee.resume_program() self.data.ecobee.resume_program(self.thermostat_index)
def set_temperature(self, temperature): def set_temperature(self, temperature):
""" Set new target temperature """ """ Set new target temperature """
@ -179,32 +180,34 @@ class Thermostat(ThermostatDevice):
low_temp = temperature - 1 low_temp = temperature - 1
high_temp = temperature + 1 high_temp = temperature + 1
if self.hold_temp: if self.hold_temp:
self.data.ecobee.set_hold_temp(low_temp, high_temp, "indefinite") self.data.ecobee.set_hold_temp(self.thermostat_index, low_temp,
high_temp, "indefinite")
else: else:
self.data.ecobee.set_hold_temp(low_temp, high_temp) self.data.ecobee.set_hold_temp(self.thermostat_index, low_temp,
high_temp)
def set_hvac_mode(self, mode): def set_hvac_mode(self, mode):
""" Set HVAC mode (auto, auxHeatOnly, cool, heat, off) """ """ Set HVAC mode (auto, auxHeatOnly, cool, heat, off) """
self.data.ecobee.set_hvac_mode(mode) self.data.ecobee.set_hvac_mode(self.thermostat_index, mode)
# 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):
# """ Turns home mode on. """ # """ Turns home mode on. """
# self._away = False # self._away = False
# self.data.ecobee.set_climate_hold("home") # self.data.ecobee.set_climate_hold(self.thermostat_index, "home")
# def turn_home_mode_off(self): # def turn_home_mode_off(self):
# """ Turns home mode off. """ # """ Turns home mode off. """
# self._away = False # self._away = False
# self.data.ecobee.resume_program() # self.data.ecobee.resume_program(self.thermostat_index)
# def turn_sleep_mode_on(self): # def turn_sleep_mode_on(self):
# """ Turns sleep mode on. """ # """ Turns sleep mode on. """
# self._away = False # self._away = False
# self.data.ecobee.set_climate_hold("sleep") # self.data.ecobee.set_climate_hold(self.thermostat_index, "sleep")
# def turn_sleep_mode_off(self): # def turn_sleep_mode_off(self):
# """ Turns sleep mode off. """ # """ Turns sleep mode off. """
# self._away = False # self._away = False
# self.data.ecobee.resume_program() # self.data.ecobee.resume_program(self.thermostat_index)

View file

@ -21,7 +21,7 @@ pysnmp==4.2.5
netdisco==0.5.2 netdisco==0.5.2
# homeassistant.components.ecobee # homeassistant.components.ecobee
https://github.com/nkgilley/python-ecobee-api/archive/d35596b67c75451fa47001c493a15eebee195e93.zip#python-ecobee==0.0.1 https://github.com/nkgilley/python-ecobee-api/archive/5645f843b64ac4f6e59dfb96233a07083c5e10c1.zip#python-ecobee==0.0.3
# homeassistant.components.ifttt # homeassistant.components.ifttt
pyfttt==0.3 pyfttt==0.3