mill1000 / midea-msmart

Python library for local control of Midea (and associated brands) smart air conditioners.
MIT License
54 stars 2 forks source link

discover dont gets Key/Token #38

Closed seppe912 closed 1 year ago

seppe912 commented 1 year ago

Hello,

i´ve been updating my Script Midea2Lox with msmart in it. I´ve updated to msmart-ng 2023.9.0 Trying to import the new discover module, and run devices = await Discover.discover() but get an error, login is empty:

Log:

29.08 07:10 asyncio DEBUG Using selector: EpollSelector
29.08 07:10 discover.py INFO Sending Device Scan Broadcast...
29.08 07:10 msmart.discover DEBUG Discovery sent to 255.255.255.255:6445.
29.08 07:10 msmart.discover DEBUG Discovery sent to 255.255.255.255:20086.
29.08 07:10 msmart.discover DEBUG Waiting 5 seconds for responses...
29.08 07:10 msmart.discover DEBUG Discovery response from 192.168.178.80: 837000b8200f04055a5a0111a8007a80000000000000000000000000a99100000012000000000000000000000000000003ed0628a5844485ef4501f937db456f370e9e5f4f939ce754af13b17d3d951c5bba106fb18ae0300ff40910de5101216d2257804fe941f9f3b7bda6c8256507f13e7784445e5328eb483a660cc2da361fca94541303884c52e880ddefc03190f31443d17c3aac03a7656614ae1dca44cce568b2ac09aeb62be232e568e8516d21bfb84f560d393142677f8172711b3b
29.08 07:10 msmart.discover DEBUG Decrypted data from 192.168.178.80: 50b2a8c02c19000030303030303050303030303030305131463043394431433137383033303030300b6e65745f61635f373830330000000001000000040000000000ac00000000000000f0c9d1c17803069fcd0300080103000000000000000000000000000000000000000000
29.08 07:10 msmart.cloud INFO Using Midea cloud server: https://mp-prod.appsmb.com (China: False).
29.08 07:10 httpx DEBUG load_ssl_context verify=True cert=None trust_env=True http2=False
29.08 07:10 httpx DEBUG load_verify_locations cafile='/opt/loxberry/bin/plugins/Midea2Lox/venv/lib/python3.9/site-packages/certifi/cacert.pem'
29.08 07:10 httpcore.connection DEBUG connect_tcp.started host='mp-prod.appsmb.com' port=443 local_address=None timeout=5.0 socket_options=None
29.08 07:10 httpcore.connection DEBUG connect_tcp.complete return_value=
29.08 07:10 httpcore.connection DEBUG start_tls.started ssl_context= server_hostname='mp-prod.appsmb.com' timeout=5.0
29.08 07:10 httpcore.connection DEBUG start_tls.complete return_value=
29.08 07:10 httpcore.http11 DEBUG send_request_headers.started request=
29.08 07:10 httpcore.http11 DEBUG send_request_headers.complete
29.08 07:10 httpcore.http11 DEBUG send_request_body.started request=
29.08 07:10 httpcore.http11 DEBUG send_request_body.complete
29.08 07:10 httpcore.http11 DEBUG receive_response_headers.started request=
29.08 07:10 httpcore.http11 DEBUG receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'', [(b'Server', b'nginx/1.17.5'), (b'Date', b'Tue, 29 Aug 2023 05:10:08 GMT'), (b'Content-Type', b'application/json'), (b'Content-Length', b'77'), (b'Connection', b'keep-alive'), (b'X-Kong-Upstream-Latency', b'5'), (b'X-Kong-Proxy-Latency', b'287'), (b'Via', b'kong/2.0.2')])
29.08 07:10 httpx INFO HTTP Request: POST https://mp-prod.appsmb.com/mas/v5/app/proxy?alias=/v1/user/login/id/get "HTTP/1.1 200 "
29.08 07:10 httpcore.http11 DEBUG receive_response_body.started request=
29.08 07:10 httpcore.http11 DEBUG receive_response_body.complete
29.08 07:10 httpcore.http11 DEBUG response_closed.started
29.08 07:10 httpcore.http11 DEBUG response_closed.complete
29.08 07:10 msmart.cloud DEBUG API response: {"code":"0","msg":"ok","data":{"loginId":"7983be2c-9fe8-4222-9e19-005236c8"}}
29.08 07:10 httpcore.connection DEBUG close.started
29.08 07:10 httpcore.connection DEBUG close.complete
29.08 07:10 msmart.cloud DEBUG Received loginId: 7983be2c-9fe8-4222-9e19-005236c8
29.08 07:10 httpx DEBUG load_ssl_context verify=True cert=None trust_env=True http2=False
29.08 07:10 httpx DEBUG load_verify_locations cafile='/opt/loxberry/bin/plugins/Midea2Lox/venv/lib/python3.9/site-packages/certifi/cacert.pem'
29.08 07:10 httpcore.connection DEBUG connect_tcp.started host='mp-prod.appsmb.com' port=443 local_address=None timeout=5.0 socket_options=None
29.08 07:10 httpcore.connection DEBUG connect_tcp.complete return_value=
29.08 07:10 httpcore.connection DEBUG start_tls.started ssl_context= server_hostname='mp-prod.appsmb.com' timeout=5.0
29.08 07:10 httpcore.connection DEBUG start_tls.complete return_value=
29.08 07:10 httpcore.http11 DEBUG send_request_headers.started request=
29.08 07:10 httpcore.http11 DEBUG send_request_headers.complete
29.08 07:10 httpcore.http11 DEBUG send_request_body.started request=
29.08 07:10 httpcore.http11 DEBUG send_request_body.complete
29.08 07:10 httpcore.http11 DEBUG receive_response_headers.started request=
29.08 07:10 msmart.discover DEBUG Discovered 1 devices.
29.08 07:10 httpcore.http11 DEBUG receive_response_headers.failed exception=ReadTimeout(TimeoutError())
29.08 07:10 httpcore.http11 DEBUG response_closed.started
29.08 07:10 httpcore.http11 DEBUG response_closed.complete
29.08 07:10 msmart.cloud WARNING Request to https://mp-prod.appsmb.com/mas/v5/app/proxy?alias=/mj/user/login timed out.
29.08 07:10 httpcore.connection DEBUG connect_tcp.started host='mp-prod.appsmb.com' port=443 local_address=None timeout=5.0 socket_options=None
29.08 07:10 httpcore.connection DEBUG connect_tcp.complete return_value=
29.08 07:10 httpcore.connection DEBUG start_tls.started ssl_context= server_hostname='mp-prod.appsmb.com' timeout=5.0
29.08 07:10 httpcore.connection DEBUG start_tls.complete return_value=
29.08 07:10 httpcore.http11 DEBUG send_request_headers.started request=
29.08 07:10 httpcore.http11 DEBUG send_request_headers.complete
29.08 07:10 httpcore.http11 DEBUG send_request_body.started request=
29.08 07:10 httpcore.http11 DEBUG send_request_body.complete
29.08 07:10 httpcore.http11 DEBUG receive_response_headers.started request=
29.08 07:10 httpcore.http11 DEBUG receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Server', b'nginx/1.17.5'), (b'Date', b'Tue, 29 Aug 2023 05:10:15 GMT'), (b'Content-Type', b'application/json;charset=UTF-8'), (b'Content-Length', b'86'), (b'Connection', b'keep-alive'), (b'Access-Control-Allow-Headers', b'access-token,x-auth-token,content-type,X-Requested-With,XMLHttpRequest'), (b'Access-Control-Allow-Methods', b'POST,GET,PUT,OPTIONS,DELETE'), (b'Access-Control-Allow-Origin', b'*'), (b'Access-Control-Max-Age', b'3600'), (b'Cache-Control', b'no-cache, no-store, max-age=0, must-revalidate'), (b'Expires', b'0'), (b'Pragma', b'no-cache'), (b'X-Application-Context', b'muc-application:7272'), (b'X-Content-Type-Options', b'nosniff'), (b'X-Frame-Options', b'DENY'), (b'X-Xss-Protection', b'1; mode=block'), (b'X-Kong-Upstream-Latency', b'1873'), (b'X-Kong-Proxy-Latency', b'282'), (b'Via', b'kong/2.0.2')])
29.08 07:10 httpx INFO HTTP Request: POST https://mp-prod.appsmb.com/mas/v5/app/proxy?alias=/mj/user/login "HTTP/1.1 200 OK"
29.08 07:10 httpcore.http11 DEBUG receive_response_body.started request=
29.08 07:10 httpcore.http11 DEBUG receive_response_body.complete
29.08 07:10 httpcore.http11 DEBUG response_closed.started
29.08 07:10 httpcore.http11 DEBUG response_closed.complete
29.08 07:10 msmart.cloud DEBUG API response: {"code":3144,"msg":"login failed, login ID is empty, please login again.","data":null}
29.08 07:10 httpcore.connection DEBUG close.started
29.08 07:10 httpcore.connection DEBUG close.complete
29.08 07:10 msmart.discover ERROR Failed to login to cloud. Error: Code: 3144, Message: login failed, login ID is empty, please login again.
29.08 07:10 msmart.discover ERROR Could not establish cloud connection.
29.08 07:10 discover.py INFO *** Found a device: {'ip': '192.168.178.80', 'port': 6444, 'id': 19791209337257, 'online': False, 'supported': False, 'type': , 'name': 'net_ac_7803', 'sn': '000000P0000000Q1F0C9D1C178030000', 'key': None, 'token': None}
...

when i try the same with midea-discover on shell, i geht this output:

midea-discover
INFO:msmart.cli:msmart version: 2023.9.0
INFO:msmart.cli:Only supports AC devices. Only supports MSmartHome and 美的美居.
INFO:msmart.cloud:Using Midea cloud server: https://mp-prod.appsmb.com (China: False).
WARNING:msmart.cloud:Request to https://mp-prod.appsmb.com/mas/v5/app/proxy?alias=/mj/user/login timed out.
ERROR:msmart.discover:Failed to login to cloud. Error: Code: 3144, Message: login failed, login ID is empty, please login again.
ERROR:msmart.discover:Could not establish cloud connection.
INFO:msmart.cli:Found 1 devices.
INFO:msmart.cli:Found device:
{'ip': '192.168.178.80', 'port': 6444, 'id': 19791209337257, 'online': False, 'supported': False, 'type': <DeviceType.AIR_CONDITIONER: 172>, 'name': 'net_ac_7803', 'sn': '000000P0000000Q1F0C9D1C178030000', 'key': None, 'token': None}

with msmart-ng 2023.8.0 it works:

`midea-discover      INFO:msmart.cli:msmart version: 2023.8.0 Currently only supports ac devices, only support MSmartHome and 美的美居 APP.
INFO:msmart.cloud:Using Midea cloud server: https://mp-prod.appsmb.com/mas/v5/app/proxy?alias= False
INFO:msmart.lan:Got TCP key for 192.168.178.46:46840 -> 192.168.178.80:6444 retries: 0 time: 0.47 tcp_key: 475147f87f69a6087eda99385e726a77444472fa4486a93b0730c5316cfb4226
INFO:msmart.cli:*** Found a device: {'name': 'net_ac_7803', 'ssid': 'net_ac_7803', 'ip': '192.168.178.80', 'port': 6444, 'id': 19791209337257, 'version': 3, 'token': 'A6A1E3C540376FE0FCEBC4843FF61C7B76C6CB4EA0A0F5CB8A97D19C8B5FAC35723EFCB96D7778A1855BC0E85CCCDE21E411879141271E31B90EA3B382937057', 'key': '6c5ca9345d1b43d4a3acfce107fb0aaee28f922120b24be09c6527eb16d1a1fc', 'type': 'ac', 'sn': '000P0000000Q1F0C9D1C178030000', 'model': '00Q1F', 'support': True, 'run_test': True}

thanks for your work!

mill1000 commented 1 year ago

Hi,

Thanks for trying the project. I've seen that error once or twice and figured it was just some transient error, but looks like you and another use have encountered it. (https://github.com/mill1000/midea-ac-py/issues/22)

Does the issue persist if you try to discover again with 2023.9.0?

mill1000 commented 1 year ago

I think I've got a fix here: #39

Care to try it out?

seppe912 commented 1 year ago

everytime i discover, its not working. I´ve tested your new code, but its still the same:

29.08 20:33 asyncio DEBUG Using selector: EpollSelector
29.08 20:33 discover.py INFO Sending Device Scan Broadcast...
29.08 20:33 msmart.discover DEBUG Discovery sent to 255.255.255.255:6445.
29.08 20:33 msmart.discover DEBUG Discovery sent to 255.255.255.255:20086.
29.08 20:33 msmart.discover DEBUG Waiting 5 seconds for responses...
29.08 20:33 msmart.discover DEBUG Discovered 0 devices.
29.08 20:33 asyncio DEBUG Using selector: EpollSelector
29.08 20:33 discover.py INFO Sending Device Scan Broadcast...
29.08 20:33 msmart.discover DEBUG Discovery sent to 255.255.255.255:6445.
29.08 20:33 msmart.discover DEBUG Discovery sent to 255.255.255.255:20086.
29.08 20:33 msmart.discover DEBUG Waiting 5 seconds for responses...
29.08 20:33 msmart.discover DEBUG Discovery response from 192.168.178.80: 837000b8200f040b5a5a0111a8007a80000000000000000000000000a99100000012000000000000000000000000000003ed0628a5844485ef4501f937db456f370e9e5f4f939ce754af13b17d3d951c5bba106fb18ae0300ff40910de5101216d2257804fe941f9f3b7bda6c8256507f13e7784445e5328eb483a660cc2da361fca94541303884c52e880ddefc03190f31443d17c3aac03a7656614ae1dca44cce568b2ac09aeb62be232e568e8516d21bfb84f560d393142677f8172711b3b
29.08 20:33 msmart.discover DEBUG Decrypted data from 192.168.178.80: 50b2a8c02c19000030303030303050303030303030305131463043394431433137383033303030300b6e65745f61635f373830330000000001000000040000000000ac00000000000000f0c9d1c17803069fcd0300080103000000000000000000000000000000000000000000
29.08 20:33 msmart.cloud INFO Using Midea cloud server: https://mp-prod.appsmb.com (China: False).
29.08 20:33 httpx DEBUG load_ssl_context verify=True cert=None trust_env=True http2=False
29.08 20:33 httpx DEBUG load_verify_locations cafile='/opt/loxberry/bin/plugins/Midea2Lox/venv/lib/python3.9/site-packages/certifi/cacert.pem'
29.08 20:33 httpcore.connection DEBUG connect_tcp.started host='mp-prod.appsmb.com' port=443 local_address=None timeout=5.0 socket_options=None
29.08 20:33 httpcore.connection DEBUG connect_tcp.complete return_value=
29.08 20:33 httpcore.connection DEBUG start_tls.started ssl_context= server_hostname='mp-prod.appsmb.com' timeout=5.0
29.08 20:33 httpcore.connection DEBUG start_tls.complete return_value=
29.08 20:33 httpcore.http11 DEBUG send_request_headers.started request=
29.08 20:33 httpcore.http11 DEBUG send_request_headers.complete
29.08 20:33 httpcore.http11 DEBUG send_request_body.started request=
29.08 20:33 httpcore.http11 DEBUG send_request_body.complete
29.08 20:33 httpcore.http11 DEBUG receive_response_headers.started request=
29.08 20:33 httpcore.http11 DEBUG receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'', [(b'Server', b'nginx/1.17.5'), (b'Date', b'Tue, 29 Aug 2023 18:33:16 GMT'), (b'Content-Type', b'application/json'), (b'Content-Length', b'77'), (b'Connection', b'keep-alive'), (b'X-Kong-Upstream-Latency', b'6'), (b'X-Kong-Proxy-Latency', b'285'), (b'Via', b'kong/2.0.2')])
29.08 20:33 httpx INFO HTTP Request: POST https://mp-prod.appsmb.com/mas/v5/app/proxy?alias=/v1/user/login/id/get "HTTP/1.1 200 "
29.08 20:33 httpcore.http11 DEBUG receive_response_body.started request=
29.08 20:33 httpcore.http11 DEBUG receive_response_body.complete
29.08 20:33 httpcore.http11 DEBUG response_closed.started
29.08 20:33 httpcore.http11 DEBUG response_closed.complete
29.08 20:33 msmart.cloud DEBUG API response: {"code":"0","msg":"ok","data":{"loginId":"a6bb0fe2-9af4-40a9-b0c3-31117858"}}
29.08 20:33 httpcore.connection DEBUG close.started
29.08 20:33 httpcore.connection DEBUG close.complete
29.08 20:33 msmart.cloud DEBUG Received loginId: a6bb0fe2-9af4-40a9-b0c3-31117858
29.08 20:33 httpx DEBUG load_ssl_context verify=True cert=None trust_env=True http2=False
29.08 20:33 httpx DEBUG load_verify_locations cafile='/opt/loxberry/bin/plugins/Midea2Lox/venv/lib/python3.9/site-packages/certifi/cacert.pem'
29.08 20:33 httpcore.connection DEBUG connect_tcp.started host='mp-prod.appsmb.com' port=443 local_address=None timeout=5.0 socket_options=None
29.08 20:33 httpcore.connection DEBUG connect_tcp.complete return_value=
29.08 20:33 httpcore.connection DEBUG start_tls.started ssl_context= server_hostname='mp-prod.appsmb.com' timeout=5.0
29.08 20:33 httpcore.connection DEBUG start_tls.complete return_value=
29.08 20:33 httpcore.http11 DEBUG send_request_headers.started request=
29.08 20:33 httpcore.http11 DEBUG send_request_headers.complete
29.08 20:33 httpcore.http11 DEBUG send_request_body.started request=
29.08 20:33 httpcore.http11 DEBUG send_request_body.complete
29.08 20:33 httpcore.http11 DEBUG receive_response_headers.started request=
29.08 20:33 msmart.discover DEBUG Discovered 1 devices.
29.08 20:33 httpcore.http11 DEBUG receive_response_headers.failed exception=ReadTimeout(TimeoutError())
29.08 20:33 httpcore.http11 DEBUG response_closed.started
29.08 20:33 httpcore.http11 DEBUG response_closed.complete
29.08 20:33 msmart.cloud WARNING Request to https://mp-prod.appsmb.com/mas/v5/app/proxy?alias=/mj/user/login timed out.
29.08 20:33 httpcore.connection DEBUG connect_tcp.started host='mp-prod.appsmb.com' port=443 local_address=None timeout=5.0 socket_options=None
29.08 20:33 httpcore.connection DEBUG connect_tcp.complete return_value=
29.08 20:33 httpcore.connection DEBUG start_tls.started ssl_context= server_hostname='mp-prod.appsmb.com' timeout=5.0
29.08 20:33 httpcore.connection DEBUG start_tls.complete return_value=
29.08 20:33 httpcore.http11 DEBUG send_request_headers.started request=
29.08 20:33 httpcore.http11 DEBUG send_request_headers.complete
29.08 20:33 httpcore.http11 DEBUG send_request_body.started request=
29.08 20:33 httpcore.http11 DEBUG send_request_body.complete
29.08 20:33 httpcore.http11 DEBUG receive_response_headers.started request=
29.08 20:33 httpcore.http11 DEBUG receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Server', b'nginx/1.17.5'), (b'Date', b'Tue, 29 Aug 2023 18:33:23 GMT'), (b'Content-Type', b'application/json;charset=UTF-8'), (b'Content-Length', b'86'), (b'Connection', b'keep-alive'), (b'Access-Control-Allow-Headers', b'access-token,x-auth-token,content-type,X-Requested-With,XMLHttpRequest'), (b'Access-Control-Allow-Methods', b'POST,GET,PUT,OPTIONS,DELETE'), (b'Access-Control-Allow-Origin', b'*'), (b'Access-Control-Max-Age', b'3600'), (b'Cache-Control', b'no-cache, no-store, max-age=0, must-revalidate'), (b'Expires', b'0'), (b'Pragma', b'no-cache'), (b'X-Application-Context', b'muc-application:7272'), (b'X-Content-Type-Options', b'nosniff'), (b'X-Frame-Options', b'DENY'), (b'X-Xss-Protection', b'1; mode=block'), (b'X-Kong-Upstream-Latency', b'1860'), (b'X-Kong-Proxy-Latency', b'284'), (b'Via', b'kong/2.0.2')])
29.08 20:33 httpx INFO HTTP Request: POST https://mp-prod.appsmb.com/mas/v5/app/proxy?alias=/mj/user/login "HTTP/1.1 200 OK"
29.08 20:33 httpcore.http11 DEBUG receive_response_body.started request=
29.08 20:33 httpcore.http11 DEBUG receive_response_body.complete
29.08 20:33 httpcore.http11 DEBUG response_closed.started
29.08 20:33 httpcore.http11 DEBUG response_closed.complete
29.08 20:33 msmart.cloud DEBUG API response: {"code":3144,"msg":"login failed, login ID is empty, please login again.","data":null}
29.08 20:33 httpcore.connection DEBUG close.started
29.08 20:33 httpcore.connection DEBUG close.complete
29.08 20:33 msmart.discover ERROR Failed to login to cloud. Error: Code: 3144, Message: login failed, login ID is empty, please login again.
29.08 20:33 msmart.discover ERROR Could not establish cloud connection.
29.08 20:33 discover.py INFO *** Found a device: {'ip': '192.168.178.80', 'port': 6444, 'id': 19791209337257, 'online': False, 'supported': False, 'type': , 'name': 'net_ac_7803', 'sn': '000000P0000000Q1F0C9D1C178030000', 'key': None, 'token': None}
mill1000 commented 1 year ago

Hm..you sure you installed from PR? Does midea-discover report a version like 2023.9.1.dev2+g29593f4?

seppe912 commented 1 year ago

Yes

midea-discover
INFO:msmart.cli:msmart version: 2023.9.1.dev2+g29593f4
INFO:msmart.cli:Only supports AC devices. Only supports MSmartHome and 美的美居.
INFO:msmart.cloud:Using Midea cloud server: https://mp-prod.appsmb.com (China: False).
WARNING:msmart.cloud:Request to https://mp-prod.appsmb.com/mas/v5/app/proxy?alias=/mj/user/login timed out.
ERROR:msmart.discover:Failed to login to cloud. Error: Code: 3144, Message: login failed, login ID is empty, please login again.
ERROR:msmart.discover:Could not establish cloud connection.
INFO:msmart.cli:Found 1 devices.
INFO:msmart.cli:Found device:
{'ip': '192.168.178.80', 'port': 6444, 'id': 19791209337257, 'online': False, 'supported': False, 'type': <DeviceType.AIR_CONDITIONER: 172>, 'name': 'net_ac_7803', 'sn': '000000P0000000Q1F0C9D1C178030000', 'key': None, 'token': None}

2023.08 works witohut any problems:

 midea-discover
INFO:msmart.cli:msmart version: 2023.8.0 Currently only supports ac devices, only support MSmartHome and 美的美居 APP.
INFO:msmart.cloud:Using Midea cloud server: https://mp-prod.appsmb.com/mas/v5/app/proxy?alias= False
INFO:msmart.lan:Got TCP key for 192.168.178.46:54978 -> 192.168.178.80:6444 retries: 0 time: 0.45 tcp_key: 6529c2c604aa5b793171a6faf961284052a60fed7aa6d09c953df90fe5c9a255
INFO:msmart.cli:*** Found a device: {'name': 'net_ac_7803', 'ssid': 'net_ac_7803', 'ip': '192.168.178.80', 'port': 6444, 'id': 19791209337257, 'version': 3, 'token': 'FDEADD6F4B4680B40E983A832E6012EC539A583112069F4359C77BA1BA6576DC4D9A17705111D39C75875465BAF71AEDFBABDA40BB11728C5F50DE88FABCE34B', 'key': '1e5cda01f99840b78b00343580b33b8b0895982641044755bfaf6cc67f53379d', 'type': 'ac', 'sn': '000P0000000Q1F0C9D1C178030000', 'model': '00Q1F', 'support': True, 'run_test': True}
mill1000 commented 1 year ago

Ok yeah, thanks.

I am able to recreate this issue if I run in a codespace in the Europe West region. Seems to work ok in the USA West and Southeast Asia regions.

mill1000 commented 1 year ago

Push a change to that PR to increase the timeout. Let me know if that helps.

seppe912 commented 1 year ago

works.

mill1000 commented 1 year ago

Closed via #39 and released in 2023.9.1