mirror of
https://github.com/no2chem/wideq.git
synced 2025-05-31 22:40:15 -07:00
Get device list
This commit is contained in:
parent
c9d67a735b
commit
705b353718
@ -59,6 +59,10 @@ def example():
|
|||||||
print_devices(session_info['item'])
|
print_devices(session_info['item'])
|
||||||
session_id = state['session_id']
|
session_id = state['session_id']
|
||||||
|
|
||||||
|
# Request a list of devices.
|
||||||
|
devices = wideq.get_devices(api_root, access_token, session_id)
|
||||||
|
print(devices)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
example()
|
example()
|
||||||
|
24
wideq.py
24
wideq.py
@ -13,6 +13,7 @@ CLIENT_ID = 'LGAO221A02'
|
|||||||
|
|
||||||
OAUTH_PATH = 'login/sign_in'
|
OAUTH_PATH = 'login/sign_in'
|
||||||
LOGIN_PATH = 'member/login'
|
LOGIN_PATH = 'member/login'
|
||||||
|
DEVICE_LIST_PATH = 'device/deviceList'
|
||||||
|
|
||||||
|
|
||||||
def gateway_info():
|
def gateway_info():
|
||||||
@ -77,14 +78,17 @@ def login(api_root, access_token):
|
|||||||
return res.json()[DATA_ROOT]
|
return res.json()[DATA_ROOT]
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
def get_devices(api_root, access_token, session_id):
|
||||||
gw = gateway_info()
|
"""Get a list of devices."""
|
||||||
oauth_base = gw['empUri']
|
|
||||||
api_root = gw['thinqUri']
|
|
||||||
print(oauth_url(oauth_base))
|
|
||||||
|
|
||||||
access_token = parse_oauth_callback(input())
|
url = urljoin(api_root + '/', DEVICE_LIST_PATH)
|
||||||
print(access_token)
|
req_data = {DATA_ROOT: {}}
|
||||||
|
headers = {
|
||||||
session_info = login(api_root, access_token)
|
'x-thinq-application-key': APP_KEY,
|
||||||
print(session_info)
|
'x-thinq-security-key': SECURITY_KEY,
|
||||||
|
'x-thinq-token': access_token,
|
||||||
|
'x-thinq-jsessionId': session_id,
|
||||||
|
'Accept': 'application/json',
|
||||||
|
}
|
||||||
|
res = requests.post(url, json=req_data, headers=headers)
|
||||||
|
return res.json()[DATA_ROOT]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user