diff --git a/example.py b/example.py index ba8d0b1..80ebab5 100644 --- a/example.py +++ b/example.py @@ -108,6 +108,12 @@ def example(args): print('setting: {}°C'.format(res['TempCfg'])) print('current: {}°C'.format(res['TempCur'])) + elif args[0] == 'set-temp': + temp = args[1] + device_id = args[2] + + session.set_device_control(device_id, 'TempCfg', temp) + except wideq.NotLoggedInError: print('Session expired.') return diff --git a/wideq.py b/wideq.py index 5c6c52b..0f1e678 100644 --- a/wideq.py +++ b/wideq.py @@ -15,6 +15,10 @@ SVC_CODE = 'SVC202' CLIENT_ID = 'LGAO221A02' +def gen_uuid(): + return str(uuid.uuid4()) + + class APIError(Exception): """An error reported by the API.""" @@ -194,12 +198,11 @@ class Session(object): monitoring. """ - input_work_id = str(uuid.uuid4()) # Why is this necessary? res = self.post('rti/rtiMon', { 'cmd': 'Mon', 'cmdOpt': 'Start', 'deviceId': device_id, - 'workId': input_work_id, + 'workId': gen_uuid(), }) return res['workId'] @@ -229,6 +232,19 @@ class Session(object): 'workId': work_id, }) + def set_device_control(self, device_id, key, value): + """Control a device's settings.""" + + res = self.post('rti/rtiControl', { + 'cmd': 'Control', + 'cmdOpt': key, + 'value': value, + 'deviceId': device_id, + 'workId': gen_uuid(), + 'data': '', + }) + print(res) + class Monitor(object): """A monitoring task for a device."""