improve support for multiple thermostats.

This commit is contained in:
nkgilley@gmail.com 2015-12-02 16:22:25 -05:00
parent 067b5862c0
commit 08de7d954a
4 changed files with 52 additions and 24 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

@ -43,18 +43,36 @@ _LOGGER = logging.getLogger(__name__)
ECOBEE_CONFIG_FILE = 'ecobee.conf' ECOBEE_CONFIG_FILE = 'ecobee.conf'
def setup_platform(hass, config, add_devices, discovery_info=None): 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
sensor_list = list()
for index in range(len(data.ecobee.thermostats)):
sensors = dict()
for sensor in data.ecobee.get_remote_sensors(index):
sensor_info = dict()
for item in sensor['capability']:
if item['type'] == 'temperature':
sensor_info['temp'] = float(item['value']) / 10
elif item['type'] == 'humidity':
sensor_info['humidity'] = item['value']
elif item['type'] == 'occupancy':
sensor_info['occupancy'] = item['value']
sensors[sensor['name']] = sensor_info
sensor_list.append(sensors)
dev = list() dev = list()
for name, data in ecobee.NETWORK.ecobee.sensors.items(): for index in range(len(sensor_list)):
if 'temp' in data: for name, data in sensor_list[index].items():
dev.append(EcobeeSensor(name, 'temperature')) if 'temp' in data:
if 'humidity' in data: dev.append(EcobeeSensor(name, 'temperature', index))
dev.append(EcobeeSensor(name, 'humidity')) if 'humidity' in data:
if 'occupancy' in data: dev.append(EcobeeSensor(name, 'humidity', index))
dev.append(EcobeeSensor(name, 'occupancy')) if 'occupancy' in data:
dev.append(EcobeeSensor(name, 'occupancy', index))
add_devices(dev) add_devices(dev)
@ -62,10 +80,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,10 +104,19 @@ class EcobeeSensor(Entity):
def update(self): def update(self):
ecobee.NETWORK.update() ecobee.NETWORK.update()
data = ecobee.NETWORK.ecobee.sensors[self.sensor_name] data = ecobee.NETWORK
for sensor in data.ecobee.get_remote_sensors(self.index):
sensor_info = dict()
for item in sensor['capability']:
if item['type'] == 'temperature':
sensor_info['temp'] = float(item['value']) / 10
elif item['type'] == 'humidity':
sensor_info['humidity'] = item['value']
elif item['type'] == 'occupancy':
sensor_info['occupancy'] = item['value']
if self.type == 'temperature': if self.type == 'temperature':
self._state = data['temp'] self._state = sensor_info['temp']
elif self.type == 'humidity': elif self.type == 'humidity':
self._state = data['humidity'] self._state = sensor_info['humidity']
elif self.type == 'occupancy': elif self.type == 'occupancy':
self._state = data['occupancy'] self._state = sensor_info['occupancy']

View File

@ -163,14 +163,14 @@ 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 """
@ -178,32 +178,32 @@ 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

@ -161,4 +161,4 @@ pushetta==1.0.15
orvibo==1.0.0 orvibo==1.0.0
# Ecobee (*.ecobee) # Ecobee (*.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