1
0
mirror of https://github.com/no2chem/wideq.git synced 2025-05-20 09:00:09 -07:00

Handle the error

This commit is contained in:
Adrian Sampson 2018-01-08 13:16:27 -08:00
parent 04b4c7a6ce
commit 5ffa880e80

View File

@ -46,6 +46,7 @@ def example():
if 'gateway' in state:
gateway = wideq.Gateway.load(state['gateway'])
else:
print('Discovering gateway servers.')
gateway = wideq.Gateway.discover()
state['gateway'] = gateway.dump()
@ -65,15 +66,21 @@ def example():
session = wideq.Session.load(auth, state['session'])
devices = None
else:
print('Starting session.')
session, devices = auth.start_session()
state['session'] = session.dump()
save_state(state)
# Request a list of devices, if we didn't get them "for free"
# already by starting the session.
if not devices:
devices = session.get_devices()
try:
# Request a list of devices, if we didn't get them "for free"
# already by starting the session.
if not devices:
devices = session.get_devices()
except wideq.NotLoggedInError:
print('Session expired.')
return
print_devices(devices)