Skip to content

Commit 6a5cce0

Browse files
committed
simplify and add support for get multiple remote sensors from diferent stats.
1 parent d35596b commit 6a5cce0

2 files changed

Lines changed: 8 additions & 23 deletions

File tree

pyecobee/__init__.py

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class Ecobee(object):
3131
''' Class for storing Ecobee Thermostats and Sensors '''
3232

3333
def __init__(self, config_filename=None, api_key=None):
34-
self.sensors = dict()
3534
self.thermostats = list()
35+
self.sensors = list()
3636
self.pin = None
3737
if config_filename is None:
3838
if api_key is None:
@@ -109,13 +109,17 @@ def get_thermostats(self):
109109
if request.status_code == requests.codes.ok:
110110
self.thermostats = request.json()['thermostatList']
111111
else:
112+
print("Error connecting to Ecobee. Refreshing tokens...")
112113
self.refresh_tokens()
113-
self.get_thermostats()
114114

115115
def get_thermostat(self, index):
116116
''' Return a single thermostat based on index '''
117117
return self.thermostats[index]
118118

119+
def get_remote_sensors(self, index):
120+
''' Get remote sensor data and store in sensors '''
121+
return self.thermostats[index]['remoteSensors']
122+
119123
def set_hvac_mode(self, hvac_mode):
120124
''' possible hvac modes are auto, auxHeatOnly, cool, heat, off '''
121125
url = 'https://api.ecobee.com/1/thermostat'
@@ -177,25 +181,6 @@ def resume_program(self, resume_all="false"):
177181
self.refresh_tokens()
178182
self.resume_program(resume_all)
179183

180-
def get_remote_sensors(self):
181-
''' Get remote sensor data and store in sensors '''
182-
try:
183-
json_sensors = self.thermostats[0]['remoteSensors']
184-
sensors = dict()
185-
for sensor in json_sensors:
186-
sensor_info = dict()
187-
for item in sensor['capability']:
188-
if item['type'] == 'temperature':
189-
sensor_info['temp'] = float(item['value']) / 10
190-
elif item['type'] == 'humidity':
191-
sensor_info['humidity'] = item['value']
192-
elif item['type'] == 'occupancy':
193-
sensor_info['occupancy'] = item['value']
194-
sensors[sensor['name']] = sensor_info
195-
self.sensors = sensors
196-
except IOError:
197-
print("Error retrieving remote sensor data.")
198-
199184
def write_tokens_to_file(self, write_sensors=False):
200185
''' Write api tokens to a file '''
201186
config = dict()
@@ -210,4 +195,4 @@ def write_tokens_to_file(self, write_sensors=False):
210195
def update(self):
211196
''' Get new thermostat data from ecobee '''
212197
self.get_thermostats()
213-
self.get_remote_sensors()
198+

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from setuptools import setup
22

33
setup(name='python-ecobee',
4-
version='0.0.1',
4+
version='0.0.2',
55
description='Python API for talking to Ecobee thermostats',
66
url='https://github.com/nkgilley/python-ecobee-api',
77
author='Nolan Gilley',

0 commit comments

Comments
 (0)