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