albertogeniola / meross-homeassistant

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

Version v1.2.10 does not support MFA #467

Closed AT181903 closed 1 month ago

AT181903 commented 8 months ago

After installing v1.2.10 when i try to set up the component, it show me "An unexpected error occurred". I tired to reinstall it removing _merosscloud folder from _customcomponents but nothing happened. Then I switched back to v1.2.8 and it worked.

Home Assistant 2023.10.3 Supervisor 2023.10.0 Operating System 11.0 Frontend 20231005.0 Hardware environment: Raspberry Pi 4

LOG:

Error Message: "An exception occurred while setting up the meross manager. Setup will be retried..."
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/meross_iot/http_api.py", line 350, in _async_authenticated_post
    error = ErrorCodes(code)
            ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/enum.py", line 712, in __call__
    return cls.__new__(cls, value)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/enum.py", line 1128, in __new__
    raise ve_exc
ValueError: 1033 is not a valid ErrorCodes

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/config/custom_components/meross_cloud/__init__.py", line 470, in async_setup_entry
    await meross_coordinator.initial_setup()
  File "/config/custom_components/meross_cloud/__init__.py", line 150, in initial_setup
    self._client, http_devices, creds_renewed = await get_or_renew_creds(
                                                ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/meross_cloud/__init__.py", line 340, in get_or_renew_creds
    http_client = await MerossHttpClient.async_from_user_password(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/meross_iot/http_api.py", line 117, in async_from_user_password
    creds = await cls.async_login(email=email,
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/meross_iot/http_api.py", line 246, in async_login
    response_data = await MerossHttpClient._async_authenticated_post(url=url,
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/meross_iot/http_api.py", line 352, in _async_authenticated_post
    raise AuthenticatedPostException(f"Unknown/Unhandled response code received from API. "
meross_iot.model.http.exception.AuthenticatedPostException: Unknown/Unhandled response code received from API. Response was: {'apiStatus': 1033, 'sysStatus': 0, 'info': '', 'timestamp': 1697888019, 'data': {}}
albertogeniola commented 8 months ago

Error 1033 stands for "MFA is required". That means you have enabled multi-factor authentication and that is not yet supported by the current version. You should either downgrade to previous version (which relied on a different API endpoint) or wait for a new release.

AT181903 commented 8 months ago

Error 1033 stands for "MFA is required". That means you have enabled multi-factor authentication and that is not yet supported by the current version. You should either downgrade to previous version (which relied on a different API endpoint) or wait for a new release.

Yes, I confirm that I have 2FA enabled on Meross account. Thanks for your reply.

albertogeniola commented 5 months ago

Glad you sorted it out :)

Japtan commented 4 months ago

Hello. I am very new to Homeassitant as I unboxed my Green box 1 week ago. So sorry if I missed something key...

I installed the version 1.2.12, and I stumbled on this MFA error. So, I downgraded to 1.2.8 and now get "Unable to connect to Meross HTTP api, ex: Failed request to API. Response code: 404". I tried both https://iotx-eu.meross.com/ and https://iot.meross.com. I think the 404 error code is misleading as I received an answer from these adresses with 1.2.12. Would it mean that Meross decomissioned the old API? Should I use another endpoint with 1.2.8? Is 1.2.12 actually supporting 2FA and I am doing something wrong? Thanks for your help.

simo1920ca commented 4 months ago

Hello. I am very new to Homeassitant as I unboxed my Green box 1 week ago. So sorry if I missed something key...

I installed the version 1.2.12, and I stumbled on this MFA error. So, I downgraded to 1.2.8 and now get "Unable to connect to Meross HTTP api, ex: Failed request to API. Response code: 404". I tried both https://iotx-eu.meross.com/ and https://iot.meross.com. I think the 404 error code is misleading as I received an answer from these adresses with 1.2.12. Would it mean that Meross decomissioned the old API? Should I use another endpoint with 1.2.8? Is 1.2.12 actually supporting 2FA and I am doing something wrong? Thanks for your help.

I've got the same issue, now i've version 1.2.10 and nothing is working

AT181903 commented 4 months ago

Hi @albertogeniola, does the version 1.2.13 support MFA?

albertogeniola commented 3 months ago

Hi @AT181903 , not yet :(

daviddst commented 2 months ago

Hi,

I don't have MFA setup on my account but I have the same error.

I've tried release 1.2.8 and latest, I couldn't use the service anymore.

Could I do something in order to restore the service ?

Thank you,

albertogeniola commented 2 months ago

Hi everybody,

I've just releases version v1.3.1beta1, which implements MFA support. It's still a beta and I need some volunteers to try it and provide feedbacks. Can anyone help?

daviddst commented 2 months ago

Hi everybody,

I've just releases version v1.3.1beta1, which implements MFA support. It's still a beta and I need some volunteers to try it and provide feedbacks. Can anyone help?

With this release, all my devices have been detected and run properly !

I'll come back here if a see any issue.

Great job, thank you very much !!!

albertogeniola commented 2 months ago

Great. I've just released a new official stable version, v1.3.1, which includes these changes. Closing for now:, but feel free to open again if needed.

AT181903 commented 2 months ago

Great. I've just released a new official stable version, v1.3.1, which includes these changes.

Closing for now:, but feel free to open again if needed.

Just updated, but it doesn't work (it tells me "An unexpected error occurred"). In addition, where does it suppose to ask me my 2FA code?

P.S. I can’t reopen the issue since I’m not repo owner, could you do it? Thank you

albertogeniola commented 2 months ago

Just updated, but it doesn't work (it tells me "An unexpected error occurred"). In addition, where does it suppose to ask me my 2FA code?

P.S. I can’t reopen the issue since I’m not repo owner, could you do it? Thank you

The 2FA code is shown only if needed/asked by the server backend. In general, when you log in without a 2FA code to an account that requires one, the server returns a specific error code. The component intercepts that error code and shows the 2FA input.

To further investigate, can you post the logs showing up when you try the authentication? It should include a detailed explanation about the error.

AT181903 commented 2 months ago

Just updated, but it doesn't work (it tells me "An unexpected error occurred"). In addition, where does it suppose to ask me my 2FA code?

P.S. I can’t reopen the issue since I’m not repo owner, could you do it? Thank you

The 2FA code is shown only if needed/asked by the server backend. In general, when you log in without a 2FA code to an account that requires one, the server returns a specific error code. The component intercepts that error code and shows the 2FA input.

To further investigate, can you post the logs showing up when you try the authentication? It should include a detailed explanation about the error.

This is the error found in homeassistant log file:

Component version: 0.4.7.1
Device info: 
<Unavailable>
Error Message: "An exception occurred while setting up the meross manager. Setup will be retried..."
Traceback (most recent call last):
  File "/config/custom_components/meross_cloud/__init__.py", line 144, in initial_setup
    self._client, http_devices, creds_renewed = await get_or_test_creds(
                                                ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/meross_cloud/__init__.py", line 342, in get_or_test_creds
    http_devices = await http_client.async_list_devices()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/meross_iot/http_api.py", line 477, in async_list_devices
    result = await MerossHttpClient._async_authenticated_post(url=url,
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/meross_iot/http_api.py", line 375, in _async_authenticated_post
    raise TokenExpiredException("The provided token has expired")
meross_iot.model.http.exception.TokenExpiredException: The provided token has expired

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/meross_cloud/__init__.py", line 421, in async_setup_entry
    await meross_coordinator.initial_setup()
  File "/config/custom_components/meross_cloud/__init__.py", line 150, in initial_setup
    raise ConfigEntryAuthFailed from err
homeassistant.exceptions.ConfigEntryAuthFailed: The provided token has expired
2024-04-28 22:16:15.289 ERROR (MainThread) [custom_components.meross_cloud.config_flow] Unable to connect to Meross HTTP api, ex: Failed request to API. Response code: 404
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 249, in async_login
    response_data = await MerossHttpClient._async_authenticated_post(url=url,
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/meross_iot/http_api.py", line 351, in _async_authenticated_post
    raise AuthenticatedPostException("Failed request to API. Response code: %s" % str(response.status))
meross_iot.model.http.exception.AuthenticatedPostException: Failed request to API. Response code: 404
2024-04-28 22:17:05.429 WARNING (MainThread) [custom_components.meross_cloud] Skip MQTT cert validation option set to: False
2024-04-28 22:17:05.660 ERROR (MainThread) [custom_components.meross_cloud] Error occurred.
-------------------------------------
AT181903 commented 2 months ago

I just tried to skip MQTT validation and it seems to work (it asked 2FA code and everything is working)