Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions wideq/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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'],
Expand Down
45 changes: 33 additions & 12 deletions wideq/core_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
"""
Expand Down Expand Up @@ -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)
Expand Down