albertogeniola / meross-homeassistant

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

Failure to add device, fixed by hack to regexp #491

Closed domob1812 closed 1 month ago

domob1812 commented 3 months ago

Describe the bug I was trying to add a new device to the Meross integration (using the local data broker add-on, too), and it always failed with "Unknown Error" and the logs shown below.

Trying my luck, I modified the regexp line, changing the expression to this:

HTTP_API_RE = re.compile("(http:\\/\\/|https:\\/\\/)?([^:]+)(:([0-9]+))?")

With this, adding the device proceeded; the data broker was not auto-configured, but I could enter it manually, and now the device seems to be working properly.

I'd be happy to provide a pull request with this change, too, but I'm not sure it is the proper change for this issue; so please let me know if you want me to do a PR, or otherwise take a look yourself.

Your environment HomeAssistant version:

Hardware environment:

Logs taken when the issue happened

2024-03-03 20:32:08.687 WARNING (MainThread) [py.warnings] /config/custom_components/meross_cloud/common.py:64: SyntaxWarning: invalid escape sequence '\/'
HTTP_API_RE = re.compile("(http:\/\/|https:\/\/)?([^:]+)(:([0-9]+))?")
2024-03-03 20:32:16.793 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 452, in _handle_request
resp = await request_handler(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 543, in _handle
resp = await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 114, in impl
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 91, in security_filter_middleware
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 235, in auth_middleware
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 31, in headers_middleware
response = await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 149, in handle
result = await handler(request, **request.match_info)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 72, in with_admin
return await func(self, request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 185, in post
return await super().post(request, flow_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 72, in wrapper
result = await method(view, request, data, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 110, in post
result = await self._flow_mgr.async_configure(flow_id, data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 358, in async_configure
result = await self._async_configure(flow_id, user_input)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 404, in _async_configure
result = await self._async_handle_step(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 501, in _async_handle_step
result: FlowResult = await getattr(flow, method)(user_input)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/meross_cloud/config_flow.py", line 197, in async_step_user
api, mqtt = await self._discover_services()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/meross_cloud/config_flow.py", line 158, in _discover_services
api_endpoint = f"http://{api_endpoint_info.server[:-1]}:{api_endpoint_info.port}"
~~~~~~~~~~~~~~~~~~~~~~~~^^^^^
TypeError: 'NoneType' object is not subscriptable
albertogeniola commented 3 months ago

Hi @domob1812 ,

I am sorry, but I am not following you. You mentioned you were trying to add a new device to the Meross integration (using the local data broker add-on, too), and it always failed with "Unknown Error" and the logs shown below.

The logs refer to the portion of code that runs when configuring the Meross integration to HomeAssistant.

Changing to the regex HTTP_API_RE would only affect this phase, so I don't understand how this helped you in enrolling the Meross device. Can you please revert the change, and provide more details and screenshot about the issue?

Thanks

domob1812 commented 3 months ago

Sorry my bad, I was describing the situation wrong (basically I had just played around until it worked, and then after the fact submitted the issue to make you aware of what I found, and didn't remember / express the details well).

tl;dr is that you are right, this is about adding the integration, not the device.

I did remove the Meross integration from my HAOS instance, so that it was in a state with the "Meross Local Broker Addon" running and the device paired to it, but not the "Meross Cloud IoT" integration added (and thus also the device not showing). That is the starting configuration.

I added the source code of this repository (release 1.2.13) without changes to my custom_components, and then tried to add the "Meross Cloud IoT" integration in the HA web frontend. This produces the "Unknown error occurred" error as per the screenshot:

Error

The logs are as in the original post.

If I make the change to the regexp, then I can add the integration per the following flow (it just complains about the auto-detect not working, but I changed the URLs to "localhost" manually, added the credentials, and it worked). The device is then added automatically since it is paired to the add-on:

Working1 Working2 Working3

albertogeniola commented 2 months ago

Hi @domob1812 ,

can you please try v1.3.1 and report if bug still exists?

Thanks

domob1812 commented 2 months ago

I can confirm the bug is gone with v1.3.1. :+1:

albertogeniola commented 1 month ago

Glad to hear that !