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:
parent
04b4c7a6ce
commit
5ffa880e80
15
example.py
15
example.py
@ -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,15 +66,21 @@ 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)
|
||||||
|
|
||||||
# Request a list of devices, if we didn't get them "for free"
|
try:
|
||||||
# already by starting the session.
|
# Request a list of devices, if we didn't get them "for free"
|
||||||
if not devices:
|
# already by starting the session.
|
||||||
devices = session.get_devices()
|
if not devices:
|
||||||
|
devices = session.get_devices()
|
||||||
|
|
||||||
|
except wideq.NotLoggedInError:
|
||||||
|
print('Session expired.')
|
||||||
|
return
|
||||||
|
|
||||||
print_devices(devices)
|
print_devices(devices)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user