mirror of
https://github.com/no2chem/wideq.git
synced 2025-05-20 17:10:19 -07:00
Unpack poll results
This commit is contained in:
parent
d09820dbbd
commit
d2735be4ad
@ -109,7 +109,8 @@ def example():
|
||||
time.sleep(1)
|
||||
print('Polling...')
|
||||
res = mon.poll()
|
||||
print(res)
|
||||
if res:
|
||||
print(res)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
14
wideq.py
14
wideq.py
@ -1,6 +1,8 @@
|
||||
import requests
|
||||
from urllib.parse import urljoin, urlencode, urlparse, parse_qs
|
||||
import uuid
|
||||
import base64
|
||||
import json
|
||||
|
||||
|
||||
GATEWAY_URL = 'https://kic.lgthinq.com:46030/api/common/gatewayUriList'
|
||||
@ -204,12 +206,18 @@ class Session(object):
|
||||
def monitor_poll(self, device_id, work_id):
|
||||
"""Get the result of a monitoring task.
|
||||
|
||||
`work_ids` is a mapping from device IDs to work IDs. Return a
|
||||
mapping from work IDs to status results.
|
||||
`work_ids` is a mapping from device IDs to work IDs. Return the
|
||||
device status or None if the monitoring is not yet ready.
|
||||
"""
|
||||
|
||||
work_list = [{'deviceId': device_id, 'workId': work_id}]
|
||||
return self.post('rti/rtiResult', {'workList': work_list})['workList']
|
||||
res = self.post('rti/rtiResult', {'workList': work_list})['workList']
|
||||
|
||||
# Weirdly, the main response data is base64-encoded JSON.
|
||||
if 'returnData' in res:
|
||||
return json.loads(base64.b64decode(res['returnData']))
|
||||
else:
|
||||
return None
|
||||
|
||||
def monitor_stop(self, device_id, work_id):
|
||||
"""Stop monitoring a device."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user