@@ -202,10 +202,6 @@ def country(self):
202202 def zipcode (self ):
203203 return self ._lyric_api ._location (self ._locationId )['zipcode' ]
204204
205- @property
206- def users (self ):
207- return self ._lyric_api ._location (self ._locationId )['user' ]
208-
209205 @property
210206 def timeZone (self ):
211207 return self ._lyric_api ._location (self ._locationId )['timeZone' ]
@@ -222,15 +218,9 @@ def geoFences(self):
222218 def geoFenceEnabled (self ):
223219 return self ._lyric_api ._location (self ._locationId )['geoFenceEnabled' ]
224220
225- # #user Array User information
226- # user.userID Integer Unique UserID
227- # user.username String User's username to login, usually an email address
228- # user.firstname String User's first name
229- # user.lastname String user last name
230- # user.created Unix Timestamp Date and time account was created in epoch format
231- # user.deleted Unix Timestamp Date and time account was deleted, negative number if not deleted
232- # user.activated Boolean True/false if user has been activated
233- # user.connectedHomeAccountExists Boolean
221+ @property
222+ def _users (self ):
223+ return self ._lyric_api ._users (self ._locationId )
234224
235225 @property
236226 def _devices (self , forceGet = False ):
@@ -244,6 +234,11 @@ def _thermostats(self):
244234 def _waterLeakDetectors (self ):
245235 return self ._lyric_api ._devices_type ('waterLeakDetectors' , self ._locationId )
246236
237+ @property
238+ def users (self ):
239+ return [User (location ['userID' ], self ._lyric_api , self ._local_time )
240+ for user in self ._users ]
241+
247242 @property
248243 def devices (self ):
249244 if 'deviceID' in self ._devices [0 ]:
@@ -280,11 +275,73 @@ def waterLeakDetectors(self):
280275 self ._lyric_api , self ._local_time ))
281276 return devices
282277
278+ class User (object ):
279+ # User information
280+ # user.userID Integer Unique UserID
281+ # user.username String User's username to login, usually an email address
282+ # user.firstname String User's first name
283+ # user.lastname String user last name
284+ # user.created Unix Timestamp Date and time account was created in epoch format
285+ # user.deleted Unix Timestamp Date and time account was deleted, negative number if not deleted
286+ # user.activated Boolean True/false if user has been activated
287+ # user.connectedHomeAccountExists Boolean
288+ def __init__ (self , locationId , userId , lyric_api , local_time = False ):
289+ self ._locationId = locationId
290+ self ._userId = userId
291+ self ._lyric_api = lyric_api
292+ self ._local_time = local_time
293+
294+ def __repr__ (self ):
295+ return '<%s: %s>' % (self .__class__ .__name__ , self ._repr_name )
296+
297+ @property
298+ def id (self ):
299+ return self ._userId
300+
301+ @property
302+ def _repr_name (self ):
303+ return self .username
304+
305+ @property
306+ def userID (self ):
307+ return self ._lyric_api ._user (self ._locationId , self ._userId )['userID' ]
308+
309+ @property
310+ def username (self ):
311+ return self ._lyric_api ._user (self ._locationId , self ._userId )['username' ]
312+
313+ @property
314+ def firstname (self ):
315+ return self ._lyric_api ._user (self ._locationId , self ._userId )['firstname' ]
316+
317+ @property
318+ def lastname (self ):
319+ return self ._lyric_api ._user (self ._locationId , self ._userId )['lastname' ]
320+
321+ @property
322+ def created (self ):
323+ return self ._lyric_api ._user (self ._locationId , self ._userId )['created' ]
324+
325+ @property
326+ def deleted (self ):
327+ return self ._lyric_api ._user (self ._locationId , self ._userId )['deleted' ]
328+
329+ @property
330+ def activated (self ):
331+ return self ._lyric_api ._user (self ._locationId , self ._userId )['activated' ]
332+
333+ @property
334+ def connectedHomeAccountExists (self ):
335+ return self ._lyric_api ._user (self ._locationId , self ._userId )['connectedHomeAccountExists' ]
336+
283337class Device (lyricDevice ):
284338 @property
285339 def unknownType (self ):
286340 return True
287341
342+ def properties (self ):
343+ return self ._lyric_api ._device (self ._locationId , self ._deviceId )
344+
288345class Thermostat (lyricDevice ):
289346 # deviceClass String Class of Device, currently "Thermostat" or "LeakDetector"
290347 # deviceType String Type of device, currently "Thermostat" or "Water Leak Detector"
@@ -789,6 +846,12 @@ def _checkCache(self, cache_key):
789846
790847 return cache
791848
849+ def _bust_cache_all (self ):
850+ self ._cache = {}
851+
852+ def _bust_cache (self , cache_key ):
853+ self ._cache [cache_key ] = (None , 0 )
854+
792855 def _location (self , locationId ):
793856 for location in self ._locations :
794857 if location ['locationID' ] == locationId :
@@ -806,11 +869,24 @@ def _locations(self):
806869
807870 return value
808871
872+ @property
873+ def _user (self , locationId , userId ):
874+ for user in self ._users (userId ):
875+ if user ['userID' ] == userId :
876+ return user
877+
878+ @property
879+ def _users (self , locationId ):
880+ value = self ._location (locationId )['user' ]
881+ return value
882+
883+ @property
809884 def _device (self , locationId , deviceId ):
810885 for device in self ._devices (locationId ):
811886 if device ['deviceID' ] == deviceId :
812887 return device
813888
889+ @property
814890 def _devices (self , locationId , forceGet = False ):
815891 if forceGet :
816892 cache_key = 'devices-%s' % locationId
@@ -825,24 +901,20 @@ def _devices(self, locationId, forceGet=False):
825901
826902 return value
827903
904+ @property
828905 def _device_type (self , locationId , deviceType , deviceId ):
829906 for device in self ._devices_type (deviceType , locationId ):
830907 if device ['deviceID' ] == deviceId :
831908 return device
832909
910+ @property
833911 def _devices_type (self , deviceType , locationId ):
834912 if not value or now - last_update > self ._cache_ttl :
835913 value = self ._get ('devices/' + deviceType , locationId = locationId )
836914 self ._cache [cache_key ] = (value , now )
837915
838916 return value
839917
840- def _bust_cache_all (self ):
841- self ._cache = {}
842-
843- def _bust_cache (self , cache_key ):
844- self ._cache [cache_key ] = (None , 0 )
845-
846918 @property
847919 def locations (self ):
848920 return [Location (location ['locationID' ], self , self ._local_time )
0 commit comments