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

Pull out the session ID

This commit is contained in:
Adrian Sampson 2018-01-06 14:26:19 -08:00
parent e79b67051c
commit c9d67a735b

View File

@ -23,6 +23,11 @@ def save_state(state):
json.dump(state, f) json.dump(state, f)
def print_devices(devices):
for device in devices:
print(device)
def example(): def example():
state = load_state() state = load_state()
@ -31,6 +36,7 @@ def example():
gw = wideq.gateway_info() gw = wideq.gateway_info()
state['oauth_base'] = gw['empUri'] state['oauth_base'] = gw['empUri']
state['api_root'] = gw['thinqUri'] state['api_root'] = gw['thinqUri']
save_state(state)
oauth_base = state['oauth_base'] oauth_base = state['oauth_base']
api_root = state['api_root'] api_root = state['api_root']
@ -42,12 +48,16 @@ def example():
print('Then paste the URL where the browser is redirected:') print('Then paste the URL where the browser is redirected:')
callback_url = input() callback_url = input()
state['access_token'] = wideq.parse_oauth_callback(callback_url) state['access_token'] = wideq.parse_oauth_callback(callback_url)
save_state(state)
access_token = state['access_token'] access_token = state['access_token']
# If we don't have a session, log in. # If we don't have a session, log in.
if 'session_id' not in state: if 'session_id' not in state:
session_info = wideq.login(api_root, access_token) session_info = wideq.login(api_root, access_token)
print(session_info) state['session_id'] = session_info['jsessionId']
save_state(state)
print_devices(session_info['item'])
session_id = state['session_id']
if __name__ == '__main__': if __name__ == '__main__':