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 = [
'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__)

View file

@ -48,14 +48,16 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
""" Sets up the sensors. """
if discovery_info is None:
return
data = ecobee.NETWORK
dev = list()
for name, data in ecobee.NETWORK.ecobee.sensors.items():
if 'temp' in data:
dev.append(EcobeeSensor(name, 'temperature'))
if 'humidity' in data:
dev.append(EcobeeSensor(name, 'humidity'))
if 'occupancy' in data:
dev.append(EcobeeSensor(name, 'occupancy'))
for index in range(len(data.ecobee.thermostats)):
for sensor in data.ecobee.get_remote_sensors(index):
for item in sensor['capability']:
if item['type'] not in ('temperature',
'humidity', 'occupancy'):
continue
dev.append(EcobeeSensor(sensor['name'], item['type'], index))
add_devices(dev)
@ -63,10 +65,11 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class EcobeeSensor(Entity):
""" 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.sensor_name = sensor_name
self.type = sensor_type
self.index = sensor_index
self._state = None
self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]
self.update()
@ -85,11 +88,22 @@ class EcobeeSensor(Entity):
return self._unit_of_measurement
def update(self):
ecobee.NETWORK.update()
data = ecobee.NETWORK.ecobee.sensors[self.sensor_name]
if self.type == 'temperature':
self._state = data['temp']
elif self.type == 'humidity':
self._state = data['humidity']
elif self.type == 'occupancy':
self._state = data['occupancy']
data = ecobee.NETWORK
data.update()
for sensor in data.ecobee.get_remote_sensors(self.index):
for item in sensor['capability']:
if (
item['type'] == self.type and
self.type == 'temperature' and
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. """
self._away = True
if self.hold_temp:
self.data.ecobee.set_climate_hold("away", "indefinite")
self.data.ecobee.set_climate_hold(self.thermostat_index,
"away", "indefinite")
else:
self.data.ecobee.set_climate_hold("away")
self.data.ecobee.set_climate_hold(self.thermostat_index, "away")
def turn_away_mode_off(self):
""" Turns away off. """
self._away = False
self.data.ecobee.resume_program()
self.data.ecobee.resume_program(self.thermostat_index)
def set_temperature(self, temperature):
""" Set new target temperature """
@ -179,32 +180,34 @@ class Thermostat(ThermostatDevice):
low_temp = temperature - 1
high_temp = temperature + 1
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:
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):
""" 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:
# def turn_home_mode_on(self):
# """ Turns home mode on. """
# 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):
# """ Turns home mode off. """
# self._away = False
# self.data.ecobee.resume_program()
# self.data.ecobee.resume_program(self.thermostat_index)
# def turn_sleep_mode_on(self):
# """ Turns sleep mode on. """
# 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):
# """ Turns sleep mode off. """
# 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
# 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
pyfttt==0.3