mirror of
https://github.com/no2chem/wideq.git
synced 2025-05-16 07:10:09 -07:00
Cache device list
This commit is contained in:
parent
948d51b1b6
commit
b2bc017d99
14
example.py
14
example.py
@ -62,6 +62,12 @@ class Client(object):
|
|||||||
self._session, self._devices = self.auth.start_session()
|
self._session, self._devices = self.auth.start_session()
|
||||||
return self._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):
|
def load(self, state):
|
||||||
"""Load the client objects from the encoded state data.
|
"""Load the client objects from the encoded state data.
|
||||||
"""
|
"""
|
||||||
@ -104,13 +110,7 @@ def example(args):
|
|||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
if not args or args[0] == 'ls':
|
if not args or args[0] == 'ls':
|
||||||
# Request a list of devices, if we didn't get them "for free"
|
for device in client.devices:
|
||||||
# already by starting the session.
|
|
||||||
devices = client._devices
|
|
||||||
if not devices:
|
|
||||||
devices = client.session.get_devices()
|
|
||||||
|
|
||||||
for device in devices:
|
|
||||||
print('{deviceId}: {alias} ({modelNm})'.format(**device))
|
print('{deviceId}: {alias} ({modelNm})'.format(**device))
|
||||||
|
|
||||||
elif args[0] == 'mon':
|
elif args[0] == 'mon':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user