nbogojevic / midea-beautiful-air

Python client for accessing Midea air conditioners and dehumidifiers (Midea, Comfee, Inventor EVO) via local network
MIT License
115 stars 18 forks source link

Adds MSmartHome to supported apps #5

Closed ethan021021 closed 2 years ago

ethan021021 commented 2 years ago

Midea recently transitioned their Midea Air app to the MSmartHome app which stops Midea accounts from working after the migration. This PR adds the app key and id to supported apps

nbogojevic commented 2 years ago

Hi @ethan021021, I'm getting sign illegal when I try to use this app key and id. I've only seen it if appkey or appid are not valid. Is there anything else that needs to be changed?

ethan021021 commented 2 years ago

Hi @ethan021021, I'm getting sign illegal when I try to use this app key and id. I've only seen it if appkey or appid are not valid. Is there anything else that needs to be changed?

Oh snap! I just added the key and ID I found in the APK. How can I go about testing the app key and id to see if it works?

nbogojevic commented 2 years ago

You can try somthing like:

midea-beautiful-air-cli --log DEBUG discover --account ACCOUNT_EMAIL --password PASSWORD --credentials --appkey c8c35003cc4c408581043baad45bce5b --appid 1010

I've also tried to dig out the new appkey/appid, but it seems to be fairly encrypted in java code in package com.midea.service.encryption.security. I've found some in js code, but they didn't work either

nbogojevic commented 2 years ago

The appkey is ac21b9f9cbfe4ca5a88562ef25**** - I'm including it in pull request.

ethan021021 commented 2 years ago

The appkey is ac21b9f9cbfe4ca5a88562ef25e2b768 - I'm including it in pull request.

Beat me to it!

ethan021021 commented 2 years ago

The appkey is ac21b9f9cbfe4ca5a88562ef25e2b768 - I'm including it in pull request.

You sure this is accurate? I'm getting a this account does not exist (3102 when trying to run the above command

nbogojevic commented 2 years ago

Do you have an account with new application? I don't, but i've seen that it doesn't recognize my account from NetHome, but I've tested another e-mail (test@gmail.com), and that one was recognized as existing, of course I don't know it's password.

ethan021021 commented 2 years ago

Do you have an account with new application?

Yes I have an account on MSmartHome

nbogojevic commented 2 years ago

I'm going to create one to test it, but it will need to wait few days.

nbogojevic commented 2 years ago

Digged a little bit deeper. The API changed significantly in this version. Login process is different so it will take more time to implement.

nbogojevic commented 2 years ago

Hi @ethan021021 I've published a new version 0.9.0 that should be able to log and discover appliances registered using MSmartHome. Could you try to see if it works. Here's example of command line that works on my side:

https://github.com/nbogojevic/midea-beautiful-air/blob/cd1c212d95ee78b13247b3f0bc4a5155022d6f8f/README.md?plain=1#L146-L150

You can find values to use in

https://github.com/nbogojevic/midea-beautiful-air/blob/5bb7b37e8835f6375e480715b0507436559aeb4f/midea_beautiful/midea.py#L37

ethan021021 commented 2 years ago

@nbogojevic Thanks for making that update! It seems to throw an error when trying to login with MSmartHome:

Unable to connect to Midea cloud API (Cloud authentication error: this account does not exist (3102)).

But my account is valid i've tried logging in/out of the MSmartApp. Thanks!

nbogojevic commented 2 years ago

hi @ethan021021 is the error from Home Assistant or from command line when using version 0.9.2 of the library?

ethan021021 commented 2 years ago

Hey @nbogojevic this is the stacktrace i'm getting from running:

midea-beautiful-air-cli --verbose ---log DEBUG discover --account ACCOUNT --password PASSWORD --credentials --appkey APPKEY --appid APPID --hmackey HMACKEY --iotkey IOTKEY --apiurl https://mp-prod.appsmb.com/mas/v5/app/proxy?alias= --proxied


  File "/opt/homebrew/bin/midea-beautiful-air-cli", line 8, in <module>
    sys.exit(cli())
  File "/opt/homebrew/lib/python3.9/site-packages/midea_beautiful/cli.py", line 339, in cli
    return function(args)
  File "/opt/homebrew/lib/python3.9/site-packages/midea_beautiful/cli.py", line 85, in _run_discover_command
    appliances = find_appliances(
  File "/opt/homebrew/lib/python3.9/site-packages/midea_beautiful/__init__.py", line 147, in find_appliances
    return do_find_appliances(
  File "/opt/homebrew/lib/python3.9/site-packages/midea_beautiful/scanner.py", line 195, in do_find_appliances
    cloud_appliances = cloud.list_appliances()
  File "/opt/homebrew/lib/python3.9/site-packages/midea_beautiful/cloud.py", line 545, in list_appliances
    self._security.aes_decrypt_string(item.get("sn"))
  File "/opt/homebrew/lib/python3.9/site-packages/midea_beautiful/crypto.py", line 585, in aes_decrypt_string
    cipher = Cipher(algorithms.AES(key.encode("utf-8")), modes.ECB())  # nosec
AttributeError: 'bytes' object has no attribute 'encode'```
nbogojevic commented 2 years ago

Thanks for report. This means the log in was successful, but there was a bug in code which tries to retrieve serial number. I've published a new version 0.9.3 with an attempt to fix decoding issue.

Could you test again with that new version. If you again have an exception, there should be some logs with HTTP exchange with MSmartHome servers. Could you add them also to the bug #6 - I've reopened it so we can use it instead of this PR.