diff --git a/example.py b/example.py index 89ff415..3822fc9 100644 --- a/example.py +++ b/example.py @@ -60,6 +60,9 @@ def mon(client, device_id): print('- {0}: {1} ({2.min}-{2.max})'.format( key, value, desc, )) + elif isinstance(desc, wideq.StringValue): + print('- {}: {}'.format(key, value)) + except KeyboardInterrupt: pass diff --git a/wideq/client.py b/wideq/client.py index a03a93e..e155567 100644 --- a/wideq/client.py +++ b/wideq/client.py @@ -297,6 +297,7 @@ def load_model_info(self): #: This is a value that is a reference to another key in the data that is at #: the same level as the `Value` key. ReferenceValue = namedtuple('ReferenceValue', ['reference']) +StringValue = namedtuple('StringValue', ['comment']) class ModelInfo(object): @@ -312,11 +313,14 @@ def value(self, name: str): :param name: The name to look up. :returns: One of (`BitValue`, `EnumValue`, `RangeValue`, `ReferenceValue`). + `ReferenceValue`, `StringValue`). :raises ValueError: If an unsupported type is encountered. """ d = self.data['Value'][name] if d['type'] in ('Enum', 'enum'): return EnumValue(d['option']) + elif d['type'] == 'String': + return StringValue(comment=d['_comment']) elif d['type'] == 'Range': return RangeValue( d['option']['min'], d['option']['max'], diff --git a/wideq/core_v2.py b/wideq/core_v2.py index 08a9511..815724b 100644 --- a/wideq/core_v2.py +++ b/wideq/core_v2.py @@ -25,6 +25,8 @@ # new V2_GATEWAY_URL = 'https://route.lgthinq.com:46030/v1/service/application/gateway-uri' OAUTH_REDIRECT_URI = 'https://kr.m.lgaccount.com/login/iabClose' +V2_AIC_ROOT = 'https://aic.lgthinq.com:46030/api' +LGEDM_DATA_ROOT = 'lgedmRoot' # orig SECURITY_KEY = 'nuts_securitykey' @@ -116,6 +118,35 @@ def thinq2_get(url, access_token=None, user_number=None, headers={}, country="US return out['result'] +def thinq2_lgedm_post(url, data=None, access_token=None, user_number=None, headers={}, country="US", language="en-US"): + headers = thinq2_headers( + access_token=access_token, + user_number=user_number, + extra_headers=headers, + country=country, + language=language) + + res = requests.post( + url, + json={LGEDM_DATA_ROOT: data}, + headers=headers) + + out = res.json()[LGEDM_DATA_ROOT] + + # Check for API errors. + if 'returnCd' in out: + code = out['returnCd'] + if code != '0000': + message = out['returnMsg'] + if code == "0102": + raise NotLoggedInError() + if code == "0106": + raise NotConnectedError() + raise APIError(code, message) + + return out + + def gateway_info(country, language): """ TODO """ @@ -267,18 +298,8 @@ def __init__(self, auth, session_id=None): self.session_id = session_id def post(self, path, data=None): - """Make a POST request to the API server. - - This is like `lgedm_post`, but it pulls the context for the - request from an active Session. - """ - - url = urljoin(self.auth.gateway.api_root + '/', path) - return lgedm_post(url, data, self.auth.access_token, self.session_id) - - def post2(self, path, data=None): - url = urljoin(self.auth.gateway.api_root + '/', path) - return lgedm_post(url, data, self.auth.access_token, self.session_id) + url = urljoin(V2_AIC_ROOT + '/', path) + return thinq2_lgedm_post(url, data, self.auth.access_token, self.auth.user_number, country=self.auth.gateway.country, language=self.auth.gateway.language) def get2(self, path): url = urljoin(self.auth.gateway.api_root + '/', path)