1
0
mirror of https://github.com/no2chem/wideq.git synced 2025-06-01 06:50:15 -07:00

Simplify retry loop

This commit is contained in:
Adrian Sampson 2018-01-20 21:39:37 -05:00
parent b2bc017d99
commit f50c8d0221

View File

@ -35,6 +35,9 @@ def authenticate(gateway):
class Client(object):
"""A higher-level API wrapper that provides a session.
"""
def __init__(self):
# The three steps required to get access to call the API.
self._gateway = None
@ -98,17 +101,7 @@ class Client(object):
self._session, self._devices = self.auth.start_session()
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:
def example_command(client, args):
if not args or args[0] == 'ls':
for device in client.devices:
print('{deviceId}: {alias} ({modelNm})'.format(**device))
@ -136,6 +129,19 @@ def example(args):
client.session.set_device_controls(device_id,
{'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
except wideq.NotLoggedInError: