NorDroN / homebridge-wideq

MIT License
12 stars 5 forks source link

Requesting Dehumidifier Support #14

Open town3r opened 4 years ago

town3r commented 4 years ago

It would be awesome if you could add in Dehumidifier support to this plugin!

Looks like the WideQ fully supports them. :)

NorDroN commented 4 years ago

It'd be great if you attach wideq-state.json file with a describe of your device. Follow this instruction and you'll get this file. I highly recommend removing your tokens from this file before sending.

town3r commented 4 years ago

Thanks for responding!

I'm running into an issue w/ getting things setup.

I get the following error after the "Then paste the URL where the browser is redirected:" setup step

https://us.m.lgaccount.com/login/iabClose?access_token=TOKEN_REMOVED&refresh_token=TOKEN_REMOVED&oauth2_backend_url=https://us.lgeapi.com/

(node:3007) UnhandledPromiseRejectionWarning: Error: write EPROTO 3069465808:error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol:../deps/openssl/openssl/ssl/statem/statem_lib.c:1942:

    at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:92:16)
(node:3007) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:3007) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Have you seen this before?

town3r commented 4 years ago

I attempted the fix here: https://github.com/sampsyo/wideq/issues/60

Downgraded the minimal tls version from tls 1.2 to 1.0 in the openssl config.

But still no go. :(

OrbitingOcelot commented 4 years ago

Heads up, on Ubuntu 20.04 I was NOT able to fix this using the various posted solutions regarding openssl.conf min TLS version, protocol version, restricted cipher suites etc.

Python always insisted on a DH key exchange which LG servers do not support, they can only do the following ciphers: AES256-GCM-SHA384 AES128-GCM-SHA256 AES256-SHA256 AES128-SHA256 AES256-SHA CAMELLIA256-SHA AES128-SHA SEED-SHA CAMELLIA128-SHA

I ended up downloading Ubuntu 18.04 in virtualbox, where the instructions worked out of the box without any messing with the config.

town3r commented 4 years ago

Were you able to transfer the config from the VM to your main box after?

I'm trying to get this setup on a RPi 4 B running the Homebridge image of Raspbian OS.

OrbitingOcelot commented 4 years ago

Were you able to transfer the config from the VM to your main box after?

The only thing you really need is to run the script ONCE, and copy the token. It was no problem to extract the refresh_token from the state file, you can even take it directly from the browser URL of the page you get redirected to after login.

Initially I was hoping to copy the refresh token directly from the URL without messing around with python/openssl further, but unfortunately this did not work, I guess the login python script does some initial configuration/registration magic on the API side that makes the whole thing work.

Fastest way I can recommend to you:

  1. Download Ubuntu 18.04 virtualbox image from https://www.osboxes.org/ubuntu/ (Ubuntu 16.04, 18.10 or 20.04 do not work as I found out...)
  2. Start the image, login, install git, clone the directory, run the script
  3. login to your gmail or whatever in firefox to transfer the URL and the token across (installing the virtualbox gueast additions is too much work for just this one task...)
  4. Success?!
town3r commented 4 years ago

One thing I just thought to try thinking it was an issue w/ Raspbian OS.

Installed a Homebridge server and wideq on my Win 10 PC.

Still getting the same error :(

C:\Windows\System32>wideq auth -c US -l en-US
Log in here: https://us.m.lgaccount.com/login/sign_in?country=US&language=en-US&svcCode=SVC202&authSvr=oauth2&client_id=LGAO221A02&division=ha&grant_type=password
Then paste the URL where the browser is redirected: https://us.m.lgaccount.com/login/iabClose?access_token=a359xxxxxxxxxxxxxxxcb6ec&refresh_token=021xxxxxxxxxxx6ba9&oauth2_backend_url=https://us.lgeapi.com/

(node:9360) UnhandledPromiseRejectionWarning: Error: write EPROTO 14188:error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol:c:\ws\deps\openssl\openssl\ssl\statem\statem_lib.c:1942:

    at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:92:16)

(node:9360) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)

(node:9360) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
town3r commented 4 years ago

Installing VirtualBox & Ubuntu 18.04 now to see if that solves the problem.

town3r commented 4 years ago

Restarting allowed me to install git and homebridge items

town3r commented 4 years ago

what commands in the VM did you specifically run on step 2? clone the directory, run the script

OrbitingOcelot commented 4 years ago

Try something along the lines of:

sudo apt-get install git git clone https://github.com/sampsyo/wideq.git cd wideq python3 example.py -c US -l en-US

(I was using the original wideq git repository here, obviously the fork should work fine too. Both are OK if all you want is to get the json token!)

town3r commented 4 years ago

oh! those steps didn't give any errors! unfortunately wideq ls and logging in there gives the error

town3r commented 4 years ago

Is this the error you were getting on the other OSs?

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 343, in _make_request
    self._validate_conn(conn)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 841, in _validate_conn
    conn.connect()
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 344, in connect
    ssl_context=context)
  File "/usr/lib/python3/dist-packages/urllib3/util/ssl_.py", line 344, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "/usr/lib/python3.7/ssl.py", line 412, in wrap_socket
    session=session
  File "/usr/lib/python3.7/ssl.py", line 853, in _create
    self.do_handshake()
  File "/usr/lib/python3.7/ssl.py", line 1117, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:1056)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 667, in urlopen
    **response_kw)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 667, in urlopen
    **response_kw)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 667, in urlopen
    **response_kw)
  [Previous line repeated 2 more times]
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 398, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='aic.lgthinq.com', port=46030): Max retries exceeded with url: /api/member/login (Caused by SSLError(SSLError(1, '[SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:1056)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "example.py", line 296, in <module>
    main()
  File "example.py", line 292, in main
    example(args.country, args.language, args.verbose, args.cmd, args.args)
  File "example.py", line 233, in example
    example_command(client, cmd, args)
  File "example.py", line 202, in example_command
    func(client, *args)
  File "example.py", line 33, in ls
    for device in client.devices:
  File "/home/pi/wideq/wideq/client.py", line 126, in devices
    self._devices = self.session.get_devices()
  File "/home/pi/wideq/wideq/client.py", line 117, in session
    self._session, self._devices = self.auth.start_session()
  File "/home/pi/wideq/wideq/core.py", line 362, in start_session
    self.gateway.country, self.gateway.language)
  File "/home/pi/wideq/wideq/core.py", line 258, in login
    return lgedm_post(url, data)
  File "/home/pi/wideq/wideq/core.py", line 202, in lgedm_post
    res = session.post(url, json={DATA_ROOT: data}, headers=headers)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 581, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 514, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='aic.lgthinq.com', port=46030): Max retries exceeded with url: /api/member/login (Caused by SSLError(SSLError(1, '[SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:1056)')))
town3r commented 4 years ago

@OrbitingOcelot after running python3 example.py -c US -l en-US did it populate a wideq_state.json with a list of your devices?

OrbitingOcelot commented 4 years ago

Yes, the file gets created on virtualbox and you can transfer it from there to get the info for your device that you need.

town3r commented 4 years ago

Hmm, maybe my dehumidifier isn't supported which is why no device gets added to the file.