Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After AC call with wideq it lock android app... #80

Open
xman123 opened this issue Jan 22, 2020 · 14 comments
Open

After AC call with wideq it lock android app... #80

xman123 opened this issue Jan 22, 2020 · 14 comments

Comments

@xman123
Copy link

xman123 commented Jan 22, 2020

After some command in wideq my AC is locked in android/ios app for few minutes, I have warning that AC using some other user...why wideq don`t close connection to API? How to fix it?

@sampsyo
Copy link
Owner

sampsyo commented Jan 22, 2020

With questions like this, the only people who can definitively answer are the API developers at LG. We are stuck guessing just as much as you! You are welcome to dive in and try to investigate yourself, but I’m afraid no one else knows any more than you.

@dacrypt
Copy link
Contributor

dacrypt commented Jan 22, 2020

I think this is related to #76

Basically LG API doesn't allow 2 users to use the api at the same time. This is true even when using only the official app provided by them.

Furthermore, I noticed that @wkd8176 in the PR #34 mentioned in the description something that might be related too: "6. Delete permission for using mobile app and HA at the same time". Maybe there's a clue there on how to deal with this.

@xman123
Copy link
Author

xman123 commented Jan 22, 2020

Yes, but when I using official app after I back to main screen I can use app on other device without warning, look like official app close connection to api on some way when we back to main screen of app...

@dacrypt
Copy link
Contributor

dacrypt commented Jan 22, 2020

This is the API call I think is doing the trick:

Request

POST https://aic.lgthinq.com:46030/api/rti/delControlPermission
{
    "lgedmRoot": {
        "deviceId": "d27c7740-7149-11d3-80b4-XXXXXXXXX"
    }
}

Response

{
    "lgedmRoot": {
        "deviceState": "E",
        "returnCd": "0000",
        "returnMsg": "OK",
        "stateCode": "S",
        "timestamp": 0,
        "workId": "n-bf1a7e3e-9824-4fee-afcb-c0000000"
    }
}

We should implement this... at the moment is beyond my knowledge on how to implement it.

@sabino
Copy link

sabino commented Jan 31, 2020

Well, this works:

client.session.post("rti/delControlPermission", {
  "deviceId": "d27bdb00-7149-11d3-80b0-XXXXXXXXXXXX"
})

Maybe add this to run always, after every command?

@dacrypt
Copy link
Contributor

dacrypt commented Jan 31, 2020

That’s probably the way to go. Can you try?

@ncovercash
Copy link
Contributor

I made a patch for this in the js variant of this repository, ssut/wideq-js#15. I do not have any experience with this library, however, maybe the patch for this will be similar?

@beele
Copy link

beele commented May 30, 2020

I have the same issue with the iOS app.
@dacrypt @ncovercash I've been trying to fix this locally in the python version

if "rtiControl" in url:
  with retry_session() as session:
    res = session.post('https://kic.lgthinq.com:46030/api/rti/delControlPermission', json={DATA_ROOT: {'deviceId': 'ID_HERE_XXXXX_XXXX_XXX'}}, headers=headers)
  temp = res
  print(temp.status_code)
  print(temp.text)

But my experiments are stuck because I'm getting a message that I'm not logged in.
Trying with this command: python3 example.py turn ID_HERE_XXXXX_XXXX_XXX off which is controlling the AC since I caan hear it beep.

The response however is:
200 {"lgedmRoot":{"returnCd":"0102","returnMsg":"Not logged in.","timestamp":0}}

For now things are hardcoded, obviously not going to keep it this way

@ncovercash
Copy link
Contributor

Hmm, that's strange. Your session is sending all the needed headers and whatnot? I had to MITM my phone and the script a lot when debugging to see what didn't line up.

@beele
Copy link

beele commented May 30, 2020

    headers = {
        'x-thinq-application-key': APP_KEY,
        'x-thinq-security-key': SECURITY_KEY,
        'Accept': 'application/json',
    }
    if access_token:
        headers['x-thinq-token'] = access_token
    if session_id:
        headers['x-thinq-jsessionId'] = session_id

    with retry_session() as session:
        res = session.post(url, json={DATA_ROOT: data}, headers=headers)
    out = res.json()[DATA_ROOT]

    if "rtiControl" in url:
        with retry_session() as session:
            res = session.post('https://kic.lgthinq.com:46030/api/rti/delControlPermission', json={DATA_ROOT: {'deviceId': 'ID_HERE_XXXXX_XXXX_XXX'}}, headers=headers)
        temp = res
        print(temp.status_code)
        print(temp.text)

    # Check for API errors.
    if 'returnCd' in out:
        code = out['returnCd']
        if code != '0000':
            message = out['returnMsg']
            if code in API_ERRORS:
                raise API_ERRORS[code](code, message)
            else:
                raise APIError(code, message)

    return out

I'm doing this in the core.py file after the post, so I'm using the same headers as the actual post to control the AC unit (which is working correctly)

@ncovercash
Copy link
Contributor

Hmm, I'm now looking at what my phone is sending and it seems like there's a new header, x-emp-token. I'm not quite sure where it comes from but without it I get the same not logged in error as you.

@beele
Copy link

beele commented May 30, 2020

Ok I figured it out by printing the actual control url, my hardcoded url was going to another instance of their API

If I use the same url (eic.lgthinq.com instead of kic.lgthinq.com) the request return 0000 as code

@ncovercash
Copy link
Contributor

Glad it's working now! Not sure why I got new issues with that x-emp-token header but I'll note what I found in a new issue, since it might be a problem later.

@beele
Copy link

beele commented May 30, 2020

I've opened a PR: #102

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants