@@ -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 )
0 commit comments