Skip to content

Commit 0ec401b

Browse files
committed
fixes
1 parent 0740c66 commit 0ec401b

2 files changed

Lines changed: 65 additions & 31 deletions

File tree

lyric/lyric.py

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __repr__(self):
2323
return '<%s: %s>' % (self.__class__.__name__, self._repr_name)
2424

2525
def _set(self, endpoint, data, **params):
26-
self._lyric_api._post(self, endpoint, data, params)
26+
self._lyric_api._post(endpoint, data, **params)
2727
self._lyric_api._bust_cache_all()
2828

2929
@property
@@ -236,7 +236,7 @@ def _waterLeakDetectors(self):
236236

237237
@property
238238
def users(self):
239-
return [User(location['userID'], self._lyric_api, self._local_time)
239+
return [User(user['userID'], self._locationId, self._lyric_api, self._local_time)
240240
for user in self._users]
241241

242242
@property
@@ -285,7 +285,7 @@ class User(object):
285285
# user.deleted Unix Timestamp Date and time account was deleted, negative number if not deleted
286286
# user.activated Boolean True/false if user has been activated
287287
# user.connectedHomeAccountExists Boolean
288-
def __init__(self, locationId, userId, lyric_api, local_time=False):
288+
def __init__(self, userId, locationId, lyric_api, local_time=False):
289289
self._locationId = locationId
290290
self._userId = userId
291291
self._lyric_api = lyric_api
@@ -298,6 +298,10 @@ def __repr__(self):
298298
def id(self):
299299
return self._userId
300300

301+
@property
302+
def name(self):
303+
return self.username
304+
301305
@property
302306
def _repr_name(self):
303307
return self.username
@@ -416,27 +420,28 @@ def indoorTemperature(self):
416420
if 'indoorTemperature' in self._lyric_api._device(self._locationId, self._deviceId):
417421
return self._lyric_api._device(self._locationId, self._deviceId)['indoorTemperature']
418422

423+
@property
424+
def temperatureSetpoint(self):
425+
if self.changeableValues['mode'] == 'Heat':
426+
return self.changeableValues['heatSetpoint']
427+
else:
428+
return self.changeableValues['coolSetpoint']
429+
419430
@temperatureSetpoint.setter
420431
def temperatureSetpoint(self, setpoint, mode=None):
421432
if mode is None:
422-
if setpoint > indoorTemperature:
433+
if setpoint > self.indoorTemperature:
423434
mode = 'Heat';
424435
else:
425436
mode = 'Cool';
426437

427438
if mode=='Cool':
428-
data = '{'
429-
'"mode": ' + mode + ','
430-
'"coolSetpoint": ' + setpoint + ','
431-
'}'
439+
data = '{"mode": %s,"coolSetpoint": %s}' % (mode, setpoint)
432440

433441
if mode=='Heat':
434-
data = '{'
435-
'"mode": ' + mode + ','
436-
'"heatSetpoint": ' + setpoint + ','
437-
'}'
442+
data = '{"mode": %s, "heatSetpoint": %s}' % (mode, setpoint)
438443

439-
self._set(self, 'devices/thermostats/' + self.deviceId, data, locationId:self._locationId):
444+
self._set('devices/thermostats/' + self._deviceId, data, locationId=self._locationId)
440445

441446
@property
442447
def outdoorTemperature(self):
@@ -891,24 +896,20 @@ def _locations(self):
891896

892897
return value
893898

894-
@property
895899
def _user(self, locationId, userId):
896-
for user in self._users(userId):
900+
for user in self._users(locationId):
897901
if user['userID'] == userId:
898902
return user
899903

900-
@property
901904
def _users(self, locationId):
902-
value = self._location(locationId)['user']
905+
value = self._location(locationId)['users']
903906
return value
904907

905-
@property
906908
def _device(self, locationId, deviceId):
907909
for device in self._devices(locationId):
908910
if device['deviceID'] == deviceId:
909911
return device
910912

911-
@property
912913
def _devices(self, locationId, forceGet=False):
913914
if forceGet:
914915
cache_key = 'devices-%s' %locationId
@@ -923,14 +924,16 @@ def _devices(self, locationId, forceGet=False):
923924

924925
return value
925926

926-
@property
927927
def _device_type(self, locationId, deviceType, deviceId):
928928
for device in self._devices_type(deviceType, locationId):
929929
if device['deviceID'] == deviceId:
930930
return device
931-
932-
@property
931+
933932
def _devices_type(self, deviceType, locationId):
933+
cache_key = 'devices_type-%s_%s' % (locationId, deviceType)
934+
value, last_update = self._checkCache(cache_key)
935+
now = time.time()
936+
934937
if not value or now - last_update > self._cache_ttl:
935938
value = self._get('devices/' + deviceType, locationId=locationId)
936939
self._cache[cache_key] = (value, now)

lyric/test.py

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,44 @@
1414
if lapi._token is None:
1515
print(lapi.getauthorize_url)
1616

17-
location = lapi.locations[0]
17+
print (lapi._locations)
18+
19+
for location in lapi.locations:
20+
print (location)
21+
print (location.id)
22+
print (location.name)
23+
print (location.city)
24+
print (location.geoFences)
25+
print (location.geoFences[0]['geoOccupancy']['withinFence'])
26+
27+
for user in location.users:
28+
print (user)
29+
print (user.id)
30+
print (user.name)
31+
print (user.firstname)
32+
print (user.lastname)
33+
34+
for device in location.devices:
35+
print (device)
36+
print (device.id)
37+
print (device.name)
38+
print (device.deviceType)
39+
print (device.indoorTemperature)
40+
print (device.temperatureSetpoint)
41+
device.temperatureSetpoint = 18
42+
43+
for thermostat in location.thermostats:
44+
print (thermostat)
45+
print (thermostat.id)
46+
print (thermostat.name)
47+
print (thermostat.deviceType)
48+
print (thermostat.outdoorTemperature)
49+
print (thermostat.indoorHumidityStatus)
50+
print (thermostat.temperatureSetpoint)
51+
52+
for waterLeakDetector in location.waterLeakDetectors:
53+
print (waterLeakDetector)
54+
print (waterLeakDetector.id)
55+
print (waterLeakDetector.name)
56+
print (waterLeakDetector.deviceType)
1857

19-
print(location.name)
20-
21-
print(location.thermostats[0].id)
22-
23-
print(location.thermostats[0].displayedOutdoorHumidity)
24-
print(location.thermostats[0].indoorTemperature)
25-
print(location.thermostats[0].outdoorTemperature)
26-
print(location.thermostats[0].indoorHumidityStatus)

0 commit comments

Comments
 (0)