albertogeniola / meross-homeassistant

Custom component that leverages the Meross IoT library to integrate with Homeassistant
MIT License
730 stars 83 forks source link

Integraion stopped working with: mfaLockExpire error #510

Open loopy321 opened 3 months ago

loopy321 commented 3 months ago

Describe the bug I was able to control the garage MSG100s for years, and it recently stopped working. I deleted and re-added the integration but just receive the mfaLockExpire message.

Your environment HomeAssistant version: 2024.8.1 Hassio Version (if applicable): HAOS 13.0 Hardware environment: intel

Logs taken when the issue happened

Traceback (most recent call last):
  File "/config/custom_components/meross_cloud/config_flow.py", line 283, in async_step_configure_manager
    creds = await self._test_authorization(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/meross_cloud/config_flow.py", line 383, in _test_authorization
    client = await MerossHttpClient.async_from_user_password(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/meross_iot/http_api.py", line 119, in async_from_user_password
    creds = await cls.async_login(email=email,
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/meross_iot/http_api.py", line 280, in async_login
    mfa_lock_expire=response_data["mfaLockExpire"],
                    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
KeyError: 'mfaLockExpire'

v. 1.3.2 of integration

[custom_components.meross_cloud.config_flow] Unable to connect to Meross HTTP api, ex: 'mfaLockExpire'

TheKingPickle007 commented 3 months ago

Yeah, getting the same thing here. Stopped working yesterday and getting the KeyError: 'mfaLockExpire' as well.

image

Logger: custom_components.meross_cloud.config_flow Source: custom_components/meross_cloud/config_flow.py:283 integration: Meross Cloud IoT First occurred: 11:07:41 AM (2 occurrences) Last logged: 5:02:57 PM

Unable to connect to Meross HTTP api, ex: 'mfaLockExpire' Traceback (most recent call last): File "/config/custom_components/meross_cloud/config_flow.py", line 283, in async_step_configure_manager creds = await self._test_authorization( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/meross_cloud/config_flow.py", line 383, in _test_authorization client = await MerossHttpClient.async_from_user_password( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/meross_iot/http_api.py", line 119, in async_from_user_password creds = await cls.async_login(email=email, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/meross_iot/http_api.py", line 280, in async_login mfa_lock_expire=response_data["mfaLockExpire"],


KeyError: 'mfaLockExpire'
Zwernemann commented 3 months ago

Same here: image

Zwernemann commented 3 months ago

OK. pip install meross_iot==0.4.7.3 solved the problem.

Pito83 commented 3 months ago

OK. pip install meross_iot==0.4.7.3 solved the problem.

Sorry for the dumb question: If I'm running meross-homeassistant (home assistant running on raspberry) I don't have an explicit installation of merossIot. This means that updating it from terminal won't fix the problem. I need to wait an update on meross-homeassistant. Am I right? Thanks

jasonwitty commented 2 months ago

@Pito83 and whomever else sees this, i took a look at the patched issue on the other repo and was able to patch meross-homeassistant using the following steps.

  1. Edit the following files in your custom_components/meross_cloud folder:

manifest.json: update version for meros_iot

{
  "domain": "meross_cloud",
  "name": "Meross Cloud IoT",
  "documentation": "https://www.home-assistant.io/components/meross_cloud",
  "issue_tracker": "https://github.com/albertogeniola/meross-homeassistant",
  "dependencies": ["persistent_notification"],
  "codeowners": ["@albertogeniola"],
  "requirements": ["meross_iot==0.4.7.3"],
  "config_flow": true,
  "quality_scale": "platinum",
  "iot_class": "cloud_push",
  "version": "1.3.2"
}

config_flow.py line 356: remove reference to mfa_lock_expire, since this is a configuration you can leave trailing comma

            CONF_STORED_CREDS: {
                "domain": creds.domain,
                "mqtt_domain": creds.mqtt_domain,
                "token": creds.token,
                "key": creds.key,
                "user_id": creds.user_id,
                "user_email": creds.user_email,
                "issued_on": creds.issued_on.isoformat(),
            },

init.py line 391: remove reference to mfa_lock_expire, since this is a constructor you do need remove preceding comma.

    creds = MerossCloudCreds(
        domain=str_creds.get("domain", MEROSS_DEFAULT_CLOUD_API_URL),
        mqtt_domain=str_creds.get("mqtt_domain"),
        token=str_creds.get("token"),
        key=str_creds.get("key"),
        user_id=str_creds.get("user_id"),
        user_email=str_creds.get("user_email"),
        issued_on=issued_on
    )
  1. remove everything from the pycache folder
 jason on jason-hyprland at …/__pycache__   sudo rm * -r
  1. restart home assistant and retry setup, you should notice a longer load time to get to configuration menu while new lib being downloaded and precompilation.

This worked for me, glhf.

xLexip commented 2 months ago

Thanks @jasonwitty. I opened a merge request for this (#514). Lets hope @albertogeniola finds time to merge this. :]

Pito83 commented 2 months ago

@Pito83 and whomever else sees this, i took a look at the patched issue on the other repo and was able to patch meross-homeassistant using the following steps.

  1. Edit the following files in your custom_components/meross_cloud folder:

manifest.json: update version for meros_iot

{
  "domain": "meross_cloud",
  "name": "Meross Cloud IoT",
  "documentation": "https://www.home-assistant.io/components/meross_cloud",
  "issue_tracker": "https://github.com/albertogeniola/meross-homeassistant",
  "dependencies": ["persistent_notification"],
  "codeowners": ["@albertogeniola"],
  "requirements": ["meross_iot==0.4.7.3"],
  "config_flow": true,
  "quality_scale": "platinum",
  "iot_class": "cloud_push",
  "version": "1.3.2"
}

config_flow.py line 356: remove reference to mfa_lock_expire, since this is a configuration you can leave trailing comma

            CONF_STORED_CREDS: {
                "domain": creds.domain,
                "mqtt_domain": creds.mqtt_domain,
                "token": creds.token,
                "key": creds.key,
                "user_id": creds.user_id,
                "user_email": creds.user_email,
                "issued_on": creds.issued_on.isoformat(),
            },

init.py line 391: remove reference to mfa_lock_expire, since this is a constructor you do need remove preceding comma.

    creds = MerossCloudCreds(
        domain=str_creds.get("domain", MEROSS_DEFAULT_CLOUD_API_URL),
        mqtt_domain=str_creds.get("mqtt_domain"),
        token=str_creds.get("token"),
        key=str_creds.get("key"),
        user_id=str_creds.get("user_id"),
        user_email=str_creds.get("user_email"),
        issued_on=issued_on
    )
  1. remove everything from the pycache folder
 jason on jason-hyprland at …/__pycache__   sudo rm * -r
  1. restart home assistant and retry setup, you should notice a longer load time to get to configuration menu while new lib being downloaded and precompilation.

This worked for me, glhf.

Thanks a lot. I've tried and it worked. Strange thing is that after some hours the controlled plugs (mss310) loose their connection with HA but still work with Meross App. I need to restart HA and they are back on duty. At least they work for some time :D

jasonwitty commented 2 months ago

np, i guess check the home assistant logs about your plugs. i only have a garage door opener from meross.

varactor commented 2 months ago

Guys I FINALLY solved it as per post 510. Make sure that you uninstall and delete everything merros_clout_iot, then 1) download from hacs 2) edit the files as per post 510 3) Go Integrations > Add Integration > Meross Clout IoT enter your credentials and you're good to go.

pugshot commented 2 months ago

Guys I FINALLY solved it as per post 510. Make sure that you uninstall and delete everything merros_clout_iot, then

  1. download from hacs
  2. edit the files as per post 510
  3. Go Integrations > Add Integration > Meross Clout IoT enter your credentials and you're good to go.

Tried this like 5 times, no luck. Even deleted the cache folder in between. Looks like this addon is no longer updated since it has been broken for almost a month.

albertogeniola commented 2 months ago

Hi all!

The KeyError: 'mfaLockExpire' error is known and is due to recent library upgrade to reflect Meross Cloud changes. Unfortunately the Local Addon plugin has not been updated yet to work with the latest MerossIot plugin. I'll try to find some time to align that to the latest changes in the next few weeks.

albertogeniola commented 2 months ago

Can you please try latest v1.3.3 and report if it's now working as expected?

ananthrajah commented 2 months ago

I just tested and still get the same error

2024-09-03 16:42:38.169273792 INFO:127.0.0.1 - - [03/Sep/2024 12:42:38] "GET /admin/events?fromTimestamp=1725381756.128 HTTP/1.0" 200 - 2024-09-03 16:42:37.386253519 INFO:127.0.0.1 - - [03/Sep/2024 12:42:37] " PUT /admin/configuration HTTP/1.0 " 500 - 2024-09-03 16:42:37.385143578 KeyError: 'mfaLockExpire' 2024-09-03 16:42:37.385142099 mfa_lock_expire=response_data["mfaLockExpire"], 2024-09-03 16:42:37.385140434 File "/usr/local/lib/python3.7/dist-packages/meross_iot/http_api.py", line 280, in async_login 2024-09-03 16:42:37.385138496 creds = await MerossHttpClient.async_login(api_base_url="https://iotx-us.meross.com", email=email, password=password) 2024-09-03 16:42:37.385136400 File "/opt/custom_broker/setup.py", line 23, in get_creds 2024-09-03 16:42:37.385134649 return future.result() 2024-09-03 16:42:37.385133181 File "/usr/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete 2024-09-03 16:42:37.385131341 return loop.run_until_complete(main) 2024-09-03 16:42:37.385129760 File "/usr/lib/python3.7/asyncio/runners.py", line 43, in run 2024-09-03 16:42:37.385128053 return asyncio.run(get_creds(email=email, password=password)) 2024-09-03 16:42:37.385126306 File "/opt/custom_broker/setup.py", line 25, in get_meross_credentials 2024-09-03 16:42:37.385124536 creds = get_meross_credentials(email=email, password=password) 2024-09-03 16:42:37.385122732 File "/opt/custom_broker/setup.py", line 33, in setup_account 2024-09-03 16:42:37.385120868 user = setup_account(email=email, password=password, enable_meross_link=meross_link) 2024-09-03 16:42:37.385119026 File "/opt/custom_broker/blueprints/admin.py", line 131, in set_account 2024-09-03 16:42:37.385117157 return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args) 2024-09-03 16:42:37.385115281 File "/usr/local/lib/python3.7/dist-packages/flask/app.py", line 1509, in dispatch_request 2024-09-03 16:42:37.385113211 rv = self.dispatch_request() 2024-09-03 16:42:37.385111430 File "/usr/local/lib/python3.7/dist-packages/flask/app.py", line 1523, in full_dispatch_request 2024-09-03 16:42:37.385109217 Traceback (most recent call last): 2024-09-03 16:42:37.385105822 ERROR:Uncaught exception: 'mfaLockExpire' 2024-09-03 16:42:37.384158686 INFO:Login successful against https://iotx-us.meross.com 2024-09-03 16:42:37.383325806 DEBUG:Response Status Code: 200 2024-09-03 16:42:37.202188251 DEBUG:Performing HTTP request against https://iotx-us.meross.com/v1/Auth/signIn, headers: {'AppVersion': '0.4.6.0', 'Authorization': 'Basic', 'vender': 'meross', 'AppType': 'MerossIOT', 'AppLanguage': 'EN', 'User-Agent': 'MerossIOT/0.4.6.0', 'Content-Type': 'application/json'}, post data: {'params': 'eyJlbWFpbCI6ICJhbmFudGgucmFqYWhAZ21haWwuY29tIiwgInBhc3N3b3JkIjogImM5MzhjYjMxMjA1MzA4MjEwMDNkYTRkMmY2NWJjMDVjIiwgImFjY291bnRDb3VudHJ5Q29kZSI6ICJ1cyIsICJlbmNyeXB0aW9uIjogMSwgImFncmVlIjogMCwgIm1vYmlsZUluZm8iOiB7ImRldmljZU1vZGVsIjogIng4Nl82NCIsICJtb2JpbGVPc1ZlcnNpb24iOiAiIzEgU01QIFBSRUVNUFRfRFlOQU1JQyBXZWQgQXVnIDIxIDE2OjI0OjU4IFVUQyAyMDI0IiwgIm1vYmlsZU9zIjogIkxpbnV4IiwgInV1aWQiOiAiNTA2NDdhOWRmNzI0MzVlZjMzNjA1MjBjNWU3NDNlZGRlYjc5NzAtM2ZkZC00NjhiLWJjMDgtYzAzMmUxYzYzMDEwIiwgImNhcnJpZXIiOiAiIn19', 'sign': 'cb3d68319e64d39fe00afadd9eb3641e', 'timestamp': 1725381757202, 'nonce': 'MDH8XHX57GHE42AV'} 2024-09-03 16:42:37.201239427 DEBUG:Using selector: EpollSelector 2024-09-03 16:42:37.201011655 INFO:Trying to federate against Meross Cloud for user

pugshot commented 2 months ago

Didn't work, I moved to Meross LAN which works.

albertogeniola commented 2 months ago

I just tested and still get the same error

2024-09-03 16:42:38.169273792 INFO:127.0.0.1 - - [03/Sep/2024 12:42:38] "GET /admin/events?fromTimestamp=1725381756.128 HTTP/1.0" 200 - 2024-09-03 16:42:37.386253519 INFO:127.0.0.1 - - [03/Sep/2024 12:42:37] " PUT /admin/configuration HTTP/1.0 " 500 - 2024-09-03 16:42:37.385143578 KeyError: 'mfaLockExpire' 2024-09-03 16:42:37.385142099 mfa_lock_expire=response_data["mfaLockExpire"], 2024-09-03 16:42:37.385140434 File "/usr/local/lib/python3.7/dist-packages/meross_iot/http_api.py", line 280, in async_login 2024-09-03 16:42:37.385138496 creds = await MerossHttpClient.async_login(api_base_url="https://iotx-us.meross.com", email=email, password=password) 2024-09-03 16:42:37.385136400 File "/opt/custom_broker/setup.py", line 23, in get_creds 2024-09-03 16:42:37.385134649 return future.result() 2024-09-03 16:42:37.385133181 File "/usr/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete 2024-09-03 16:42:37.385131341 return loop.run_until_complete(main) 2024-09-03 16:42:37.385129760 File "/usr/lib/python3.7/asyncio/runners.py", line 43, in run 2024-09-03 16:42:37.385128053 return asyncio.run(get_creds(email=email, password=password)) 2024-09-03 16:42:37.385126306 File "/opt/custom_broker/setup.py", line 25, in get_meross_credentials 2024-09-03 16:42:37.385124536 creds = get_meross_credentials(email=email, password=password) 2024-09-03 16:42:37.385122732 File "/opt/custom_broker/setup.py", line 33, in setup_account 2024-09-03 16:42:37.385120868 user = setup_account(email=email, password=password, enable_meross_link=meross_link) 2024-09-03 16:42:37.385119026 File "/opt/custom_broker/blueprints/admin.py", line 131, in set_account 2024-09-03 16:42:37.385117157 return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args) 2024-09-03 16:42:37.385115281 File "/usr/local/lib/python3.7/dist-packages/flask/app.py", line 1509, in dispatch_request 2024-09-03 16:42:37.385113211 rv = self.dispatch_request() 2024-09-03 16:42:37.385111430 File "/usr/local/lib/python3.7/dist-packages/flask/app.py", line 1523, in full_dispatch_request 2024-09-03 16:42:37.385109217 Traceback (most recent call last): 2024-09-03 16:42:37.385105822 ERROR:Uncaught exception: 'mfaLockExpire' 2024-09-03 16:42:37.384158686 INFO:Login successful against https://iotx-us.meross.com 2024-09-03 16:42:37.383325806 DEBUG:Response Status Code: 200 2024-09-03 16:42:37.202188251 DEBUG:Performing HTTP request against https://iotx-us.meross.com/v1/Auth/signIn, headers: {'AppVersion': '0.4.6.0', 'Authorization': 'Basic', 'vender': 'meross', 'AppType': 'MerossIOT', 'AppLanguage': 'EN', 'User-Agent': 'MerossIOT/0.4.6.0', 'Content-Type': 'application/json'}, post data: {'params': 'eyJlbWFpbCI6ICJhbmFudGgucmFqYWhAZ21haWwuY29tIiwgInBhc3N3b3JkIjogImM5MzhjYjMxMjA1MzA4MjEwMDNkYTRkMmY2NWJjMDVjIiwgImFjY291bnRDb3VudHJ5Q29kZSI6ICJ1cyIsICJlbmNyeXB0aW9uIjogMSwgImFncmVlIjogMCwgIm1vYmlsZUluZm8iOiB7ImRldmljZU1vZGVsIjogIng4Nl82NCIsICJtb2JpbGVPc1ZlcnNpb24iOiAiIzEgU01QIFBSRUVNUFRfRFlOQU1JQyBXZWQgQXVnIDIxIDE2OjI0OjU4IFVUQyAyMDI0IiwgIm1vYmlsZU9zIjogIkxpbnV4IiwgInV1aWQiOiAiNTA2NDdhOWRmNzI0MzVlZjMzNjA1MjBjNWU3NDNlZGRlYjc5NzAtM2ZkZC00NjhiLWJjMDgtYzAzMmUxYzYzMDEwIiwgImNhcnJpZXIiOiAiIn19', 'sign': 'cb3d68319e64d39fe00afadd9eb3641e', 'timestamp': 1725381757202, 'nonce': 'MDH8XHX57GHE42AV'} 2024-09-03 16:42:37.201239427 DEBUG:Using selector: EpollSelector 2024-09-03 16:42:37.201011655 INFO:Trying to federate against Meross Cloud for user

That happens because you are referring to the local-addon. You should open an issue on the other repository. In any case, this is a duplicate of https://github.com/albertogeniola/ha-meross-local-broker/issues/51.

douglascamata commented 2 weeks ago

I just updated my integration to 1.3.3 and it bricked my whole Home Assistant with this error.

douglascamata commented 2 weeks ago

After I manually edited the code to revert the changes from afe10ef22d137bab920bea908f1cfd4bc03255f6, the problem disappeared.