mirror of
https://github.com/no2chem/wideq.git
synced 2025-05-21 09:30:13 -07:00
Unpack poll results
This commit is contained in:
parent
d09820dbbd
commit
d2735be4ad
@ -109,6 +109,7 @@ def example():
|
|||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
print('Polling...')
|
print('Polling...')
|
||||||
res = mon.poll()
|
res = mon.poll()
|
||||||
|
if res:
|
||||||
print(res)
|
print(res)
|
||||||
|
|
||||||
|
|
||||||
|
14
wideq.py
14
wideq.py
@ -1,6 +1,8 @@
|
|||||||
import requests
|
import requests
|
||||||
from urllib.parse import urljoin, urlencode, urlparse, parse_qs
|
from urllib.parse import urljoin, urlencode, urlparse, parse_qs
|
||||||
import uuid
|
import uuid
|
||||||
|
import base64
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
GATEWAY_URL = 'https://kic.lgthinq.com:46030/api/common/gatewayUriList'
|
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):
|
def monitor_poll(self, device_id, work_id):
|
||||||
"""Get the result of a monitoring task.
|
"""Get the result of a monitoring task.
|
||||||
|
|
||||||
`work_ids` is a mapping from device IDs to work IDs. Return a
|
`work_ids` is a mapping from device IDs to work IDs. Return the
|
||||||
mapping from work IDs to status results.
|
device status or None if the monitoring is not yet ready.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
work_list = [{'deviceId': device_id, 'workId': work_id}]
|
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):
|
def monitor_stop(self, device_id, work_id):
|
||||||
"""Stop monitoring a device."""
|
"""Stop monitoring a device."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user