1
0
mirror of https://github.com/no2chem/wideq.git synced 2025-05-15 23:00:18 -07:00

Cache device list

This commit is contained in:
Adrian Sampson 2018-01-20 21:35:09 -05:00
parent 948d51b1b6
commit b2bc017d99

View File

@ -62,6 +62,12 @@ class Client(object):
self._session, self._devices = self.auth.start_session()
return self._session
@property
def devices(self):
if not self._devices:
self._devices = self.session.get_devices()
return self._devices
def load(self, state):
"""Load the client objects from the encoded state data.
"""
@ -104,13 +110,7 @@ def example(args):
while True:
try:
if not args or args[0] == 'ls':
# Request a list of devices, if we didn't get them "for free"
# already by starting the session.
devices = client._devices
if not devices:
devices = client.session.get_devices()
for device in devices:
for device in client.devices:
print('{deviceId}: {alias} ({modelNm})'.format(**device))
elif args[0] == 'mon':