petretiandrea / home-assistant-tapo-p100

A custom integration to control Tapo devices from home assistant.
MIT License
811 stars 101 forks source link

"Failed to connect" or "Unknown error occurred" when trying to connect to device #776

Closed samueljsh closed 2 weeks ago

samueljsh commented 3 months ago

Version of the integration

v3.1.2

Configuration

Tapo L630. Firmware: 1.1.0 Build 230823 Rel. 165100

Describe the bug

I keep receiving a "Failed to connect" or "Unknown error occurred" when trying to connect to devices. I've installed the integration via HACS and have not been able to get much further due to these errors.

I've perused most of the issues and can't find a similar topic. I've confirmed that neither my username or password contain uppercase characters. The errors are always the same, even when testing with incorrect IP, username or password variations.

I am able to ping the devices successfully on port 80 via various network devices, including the device running home assistant.

Debug log

2024-06-08 02:29:05.861 ERROR (MainThread) [custom_components.tapo.config_flow] Failed to setup cannot connect Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1025, in _wrap_create_connection return await self._loop.create_connection(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1120, in create_connection raise exceptions[0] File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1102, in create_connection sock = await self._connect_sock( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1005, in _connect_sock await self.sock_connect(sock, address) File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 641, in sock_connect return await fut ^^^^^^^^^ File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 681, in _sock_connect_cb raise OSError(err, f'Connect call failed {address}') TimeoutError: [Errno 110] Connect call failed ('192.168.5.149', 80)

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

Traceback (most recent call last): File "/config/custom_components/tapo/config_flow.py", line 314, in _async_get_device device = await connect(config=config, session=session) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/plugp100/new/device_factory.py", line 43, in connect protocol = await _get_or_guess_protocol(config, session) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/plugp100/new/device_factory.py", line 65, in _get_or_guess_protocol return await _guess_protocol(config, session) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/plugp100/new/device_factory.py", line 94, in _guess_protocol info = await protocol.send_request(device_info_request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/plugp100/protocol/passthrough_protocol.py", line 45, in send_request response = await self._send_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/plugp100/protocol/passthrough_protocol.py", line 65, in _send_request await self._login_with_version(self._credential) File "/usr/local/lib/python3.12/site-packages/plugp100/protocol/passthrough_protocol.py", line 84, in _login_with_version session_or_error = await self._passthrough.handshake(self._url) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/plugp100/protocol/securepassthrough_transport.py", line 70, in handshake response = await self._http.async_make_post(url, json=request_body) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/plugp100/common/utils/http_client.py", line 18, in async_make_post async with self.session.post( File "/usr/local/lib/python3.12/site-packages/aiohttp/client.py", line 1197, in aenter self._resp = await self._coro ^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/aiohttp/client.py", line 581, in _request conn = await self._connector.connect( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 544, in connect proto = await self._create_connection(req, traces, timeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 944, in _createconnection , proto = await self._create_direct_connection(req, traces, timeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1257, in _create_direct_connection raise last_exc File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1226, in _create_direct_connection transp, proto = await self._wrap_create_connection( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1033, in _wrap_create_connection raise client_error(req.connection_key, exc) from exc aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host 192.168.5.149:80 ssl:default [Connect call failed ('192.168.5.149', 80)]

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

Traceback (most recent call last): File "/config/custom_components/tapo/config_flow.py", line 143, in async_step_user device = await self._async_get_device(user_input) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/tapo/config_flow.py", line 322, in _async_get_device raise CannotConnect from error custom_components.tapo.errors.CannotConnect

jonathanoakley commented 3 months ago

I'm getting a similar error, but is device dependent. I can add a smart plug just fine, then discovery will bring up all the other different TAPO products that I have, but if I try to add a hub or a non smart switch, I get the error message you reported above.

This error originated from a custom integration.

Logger: custom_components.tapo.config_flow
Source: custom_components/tapo/config_flow.py:231
integration: TP-Link Tapo (documentation, issues)
First occurred: 13:35:49 (1 occurrences)
Last logged: 13:35:49

Failed to setup cannot connect
Traceback (most recent call last):
  File "/config/custom_components/tapo/config_flow.py", line 317, in _async_get_device
    await device.update()
  File "/usr/local/lib/python3.12/site-packages/plugp100/new/tapodevice.py", line 79, in update
    await component.update(state)
  File "/usr/local/lib/python3.12/site-packages/plugp100/new/components/hub_children_component.py", line 47, in update
    await child_device.update()
  File "/usr/local/lib/python3.12/site-packages/plugp100/new/tapodevice.py", line 79, in update
    await component.update(state)
  File "/usr/local/lib/python3.12/site-packages/plugp100/new/components/smart_door_component.py", line 15, in update
    self.is_open = current_state["is_open"]
                   ~~~~~~~~~~~~~^^^^^^^^^^^
KeyError: 'is_open'

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

Traceback (most recent call last):
  File "/config/custom_components/tapo/config_flow.py", line 231, in async_step_discovery_auth_confirm
    device = await self._async_get_device_from_discovered(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/tapo/config_flow.py", line 295, in _async_get_device_from_discovered
    return await self._async_get_device(config | {CONF_HOST: discovered.ip}, discovered)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/tapo/config_flow.py", line 322, in _async_get_device
    raise CannotConnect from error
custom_components.tapo.errors.CannotConnect

I should add that the devices have been working previously.

samueljsh commented 3 months ago

I'm getting a similar error, but is device dependent. I can add a smart plug just fine, then discovery will bring up all the other different TAPO products that I have, but if I try to add a hub or a non smart switch, I get the error message you reported above.

This error originated from a custom integration.

Logger: custom_components.tapo.config_flow
Source: custom_components/tapo/config_flow.py:231
integration: TP-Link Tapo (documentation, issues)
First occurred: 13:35:49 (1 occurrences)
Last logged: 13:35:49

Failed to setup cannot connect
Traceback (most recent call last):
  File "/config/custom_components/tapo/config_flow.py", line 317, in _async_get_device
    await device.update()
  File "/usr/local/lib/python3.12/site-packages/plugp100/new/tapodevice.py", line 79, in update
    await component.update(state)
  File "/usr/local/lib/python3.12/site-packages/plugp100/new/components/hub_children_component.py", line 47, in update
    await child_device.update()
  File "/usr/local/lib/python3.12/site-packages/plugp100/new/tapodevice.py", line 79, in update
    await component.update(state)
  File "/usr/local/lib/python3.12/site-packages/plugp100/new/components/smart_door_component.py", line 15, in update
    self.is_open = current_state["is_open"]
                   ~~~~~~~~~~~~~^^^^^^^^^^^
KeyError: 'is_open'

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

Traceback (most recent call last):
  File "/config/custom_components/tapo/config_flow.py", line 231, in async_step_discovery_auth_confirm
    device = await self._async_get_device_from_discovered(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/tapo/config_flow.py", line 295, in _async_get_device_from_discovered
    return await self._async_get_device(config | {CONF_HOST: discovered.ip}, discovered)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/tapo/config_flow.py", line 322, in _async_get_device
    raise CannotConnect from error
custom_components.tapo.errors.CannotConnect

I should add that the devices have been working previously.

I've managed to add the bulbs to the Samsung SmartThings app and connected SmartThings to Home Assistant. It's one additional hop, but the downlights were never going to be 100% local (can't find any downlights with similar specs outside of Hue).

This at least provides a reliable means to control the downlights (with minimal lag) from Home Assistant until a solution can be found here.

Danconnolly commented 3 months ago

I'm getting a similar error, but is device dependent. I can add a smart plug just fine, ... File "/usr/local/lib/python3.12/site-packages/plugp100/new/components/smart_door_component.py", line 15, in update self.is_open = current_state["is_open"]


KeyError: 'is_open'

This is a duplicate of https://github.com/petretiandrea/home-assistant-tapo-p100/issues/759 and is fixed by pull request https://github.com/petretiandrea/plugp100/pull/189

hazzabeee commented 3 months ago

@samueljsh Is the device actually at 192.168.5.149? I encountered a bug where the integration would try to connect to the device at config["discovered_device_info"]["ip"] - the original IP address the device was discovered at - rather than config["host"] - the current IP address. Perhaps related?

samueljsh commented 3 months ago

@samueljsh Is the device actually at 192.168.5.149? I encountered a bug where the integration would try to connect to the device at config["discovered_device_info"]["ip"] - the original IP address the device was discovered at - rather than config["host"] - the current IP address. Perhaps related?

It was the actual device IP address. I have 10 of these downlights throughout the house and their IP addresses can be viewed in the Tapo app and the router config. I've tried with various of these devices and their respective IP's, and received the same results.

github-actions[bot] commented 2 months ago

This issue is stale because it has been open for 30 days with no activity.

msoaresp commented 2 months ago

O mesmo acontece comigo. Estou usando outra integração que está funcionando normal, mas queria usar esta. Segue meu log

This error originated from a custom integration.

Logger: custom_components.tapo.config_flow
Source: custom_components/tapo/config_flow.py:143
integration: TP-Link Tapo (documentation, issues)
First occurred: 20:39:57 (2 occurrences)
Last logged: 20:40:19

Failed to setup cannot connect
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1025, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1122, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1104, in create_connection
    sock = await self._connect_sock(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1007, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 641, in sock_connect
    return await fut
           ^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 681, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('192.168.68.42', 80)

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

Traceback (most recent call last):
  File "/config/custom_components/tapo/config_flow.py", line 314, in _async_get_device
    device = await connect(config=config, session=session)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/plugp100/new/device_factory.py", line 43, in connect
    protocol = await _get_or_guess_protocol(config, session)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/plugp100/new/device_factory.py", line 65, in _get_or_guess_protocol
    return await _guess_protocol(config, session)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/plugp100/new/device_factory.py", line 94, in _guess_protocol
    info = await protocol.send_request(device_info_request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/plugp100/protocol/passthrough_protocol.py", line 45, in send_request
    response = await self._send_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/plugp100/protocol/passthrough_protocol.py", line 65, in _send_request
    await self._login_with_version(self._credential)
  File "/usr/local/lib/python3.12/site-packages/plugp100/protocol/passthrough_protocol.py", line 84, in _login_with_version
    session_or_error = await self._passthrough.handshake(self._url)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/plugp100/protocol/securepassthrough_transport.py", line 70, in handshake
    response = await self._http.async_make_post(url, json=request_body)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/plugp100/common/utils/http_client.py", line 18, in async_make_post
    async with self.session.post(
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client.py", line 1197, in __aenter__
    self._resp = await self._coro
                 ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client.py", line 581, in _request
    conn = await self._connector.connect(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 544, in connect
    proto = await self._create_connection(req, traces, timeout)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 944, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1257, in _create_direct_connection
    raise last_exc
  File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1226, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1033, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host 192.168.68.42:80 ssl:default [Connect call failed ('192.168.68.42', 80)]

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

Traceback (most recent call last):
  File "/config/custom_components/tapo/config_flow.py", line 143, in async_step_user
    device = await self._async_get_device(user_input)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/tapo/config_flow.py", line 322, in _async_get_device
    raise CannotConnect from error
custom_components.tapo.errors.CannotConnect
github-actions[bot] commented 1 month ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 2 weeks ago

This issue was closed because it has been inactive for 14 days since being marked as stale.