mirror of
https://github.com/no2chem/wideq.git
synced 2025-06-02 23:40:15 -07:00
Simplify retry loop
This commit is contained in:
parent
b2bc017d99
commit
f50c8d0221
28
example.py
28
example.py
@ -35,6 +35,9 @@ def authenticate(gateway):
|
|||||||
|
|
||||||
|
|
||||||
class Client(object):
|
class Client(object):
|
||||||
|
"""A higher-level API wrapper that provides a session.
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# The three steps required to get access to call the API.
|
# The three steps required to get access to call the API.
|
||||||
self._gateway = None
|
self._gateway = None
|
||||||
@ -98,17 +101,7 @@ class Client(object):
|
|||||||
self._session, self._devices = self.auth.start_session()
|
self._session, self._devices = self.auth.start_session()
|
||||||
|
|
||||||
|
|
||||||
def example(args):
|
def example_command(client, args):
|
||||||
state = load_state()
|
|
||||||
client = Client()
|
|
||||||
client.load(state)
|
|
||||||
|
|
||||||
if not client._auth:
|
|
||||||
client._auth = authenticate(client.gateway)
|
|
||||||
|
|
||||||
# Loop to retry if session has expired.
|
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
if not args or args[0] == 'ls':
|
if not args or args[0] == 'ls':
|
||||||
for device in client.devices:
|
for device in client.devices:
|
||||||
print('{deviceId}: {alias} ({modelNm})'.format(**device))
|
print('{deviceId}: {alias} ({modelNm})'.format(**device))
|
||||||
@ -136,6 +129,19 @@ def example(args):
|
|||||||
client.session.set_device_controls(device_id,
|
client.session.set_device_controls(device_id,
|
||||||
{'TempCfg': temp})
|
{'TempCfg': temp})
|
||||||
|
|
||||||
|
|
||||||
|
def example(args):
|
||||||
|
state = load_state()
|
||||||
|
client = Client()
|
||||||
|
client.load(state)
|
||||||
|
|
||||||
|
if not client._auth:
|
||||||
|
client._auth = authenticate(client.gateway)
|
||||||
|
|
||||||
|
# Loop to retry if session has expired.
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
example_command(client, args)
|
||||||
break
|
break
|
||||||
|
|
||||||
except wideq.NotLoggedInError:
|
except wideq.NotLoggedInError:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user