Skip to content

Commit

Permalink
Fix for invalid login (issue #3)
Browse files Browse the repository at this point in the history
- set SSL version to TLSv1
- added error log
  • Loading branch information
ollo69 committed Mar 31, 2020
1 parent c8ed7a6 commit 64631bf
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions custom_components/smartthinq_washer/wideq.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import ssl
import requests
from urllib3.poolmanager import PoolManager
from requests.adapters import HTTPAdapter
from urllib.parse import urljoin, urlencode, urlparse, parse_qs
import uuid
import base64
Expand Down Expand Up @@ -27,6 +30,13 @@
class STATE_UNKNOWN(enum.Enum):
UNKNOWN = 'unknown'

class Tlsv1HttpAdapter(HTTPAdapter):
def init_poolmanager(self, connections, maxsize, block=False):
self.poolmanager = PoolManager(
num_pools=connections, maxsize=maxsize,
block=block, ssl_version=ssl.PROTOCOL_TLSv1)


GATEWAY_URL = 'https://kic.lgthinq.com:46030/api/common/gatewayUriList'
APP_KEY = 'wideq'
SECURITY_KEY = 'nuts_securitykey'
Expand Down Expand Up @@ -136,8 +146,17 @@ def lgedm_post(url, data=None, access_token=None, session_id=None):
if session_id:
headers['x-thinq-jsessionId'] = session_id

res = requests.post(url, json={DATA_ROOT: data}, headers=headers, timeout = DEFAULT_TIMEOUT)
try:
s = requests.Session()
s.mount(url, Tlsv1HttpAdapter())
res = s.post(url, json={DATA_ROOT: data}, headers=headers, timeout = DEFAULT_TIMEOUT)
#res = requests.post(url, json={DATA_ROOT: data}, headers=headers, timeout = DEFAULT_TIMEOUT)
except Exception as ex:
_LOGGER.error(ex)
raise

out = res.json()[DATA_ROOT]
_LOGGER.debug(out)

# Check for API errors.
if 'returnCd' in out:
Expand All @@ -151,7 +170,6 @@ def lgedm_post(url, data=None, access_token=None, session_id=None):
else:
raise APIError(code, message)


return out


Expand Down Expand Up @@ -254,8 +272,17 @@ def refresh_auth(oauth_root, refresh_token):
'Accept': 'application/json',
}

res = requests.post(token_url, data=data, headers=headers, timeout = DEFAULT_REFRESH_TIMEOUT)
try:
s = requests.Session()
s.mount(token_url, Tlsv1HttpAdapter())
res = s.post(token_url, data=data, headers=headers, timeout = DEFAULT_REFRESH_TIMEOUT)
#res = requests.post(token_url, data=data, headers=headers, timeout = DEFAULT_REFRESH_TIMEOUT)
except Exception as ex:
_LOGGER.error(ex)
raise

res_data = res.json()
_LOGGER.debug(res_data)

if res_data['status'] != 1:
raise TokenError()
Expand Down

4 comments on commit 64631bf

@AbsoluteMidnight
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this as suggested in the issue about invalid login, but still get Invalid SmartThinQ credentials.

@ollo69
Copy link
Owner Author

@ollo69 ollo69 commented on 64631bf Apr 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you so other error in the log (should be what is logged in the exception). Can you post it?

@AbsoluteMidnight
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my log i just see this:
2020-04-01 10:43:28 ERROR (MainThread) [custom_components.smartthinq_washer.config_flow] LGE Washer: Invalid Login info!

If i try the other method, adding manually in configuration.yaml, when i go in the integrations page there is a box above the list that warns me about a new integration found (SmartThinQ etc) and the link to configure it, but clicking it i just go back to the usual UI that gives me the "Invalid SmartThinQ credentials." error

@ollo69
Copy link
Owner Author

@ollo69 ollo69 commented on 64631bf Apr 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need more info to try to help you,

  • are you sure you are running last version (how you install it)?
  • what is your environment (Harsware, OS, version of HA...)
  • what info do you fill in the setuo screen?
  • are you able to create the new token?

Please answer inside the issue #3 so that everybody can read and not here in the commit, I lock this conversation to continue in the issue.

Thx.

Please sign in to comment.