ekutner / home-connect-hass

Alternative (and improved) Home Connect integration for Home Assistant
MIT License
593 stars 57 forks source link

ConnectionError in SSE event stream. failed: 409 #203

Closed nordeep closed 1 year ago

nordeep commented 1 year ago

Describe the bug

After successfully added DishWasher from Home Connect to HA all entities available only once. In logs i can see next error:

ConnectionError: fetch https://api.home-connect.com/api/homeappliances/events failed: 409

If I toggle Turn on switch from HA I see as Dish Washer turn on, but state of switch doesn't update. Only if I press Home Connect Refresh button all states will be updated. Home Connect Status always LOADED.

Version of the custom_component

Configuration

home_connect_alt:
  client_id: !hc_client_id
  client_secret: !hc_client_secret

Debug log

2023-04-08 12:57:58.984 DEBUG (MainThread) [home_connect_async.homeconnect] Connecting to SSE stream
2023-04-08 12:57:59.378 ERROR (MainThread) [aiohttp_sse_client.client] fetch https://api.home-connect.com/api/homeappliances/events failed: 409
2023-04-08 12:57:59.379 DEBUG (MainThread) [home_connect_async.homeconnect] ConnectionError in SSE event stream. Will wait for 120 seconds and retry
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/home_connect_async/homeconnect.py", line 248, in async_events_stream
    await event_source.connect()
  File "/usr/local/lib/python3.10/site-packages/aiohttp_sse_client/client.py", line 244, in connect
    raise ConnectionError(error_message)
ConnectionError: fetch https://api.home-connect.com/api/homeappliances/events failed: 409
ekutner commented 1 year ago

See the README for why this happens. Nothing much to do about it except wait.

nordeep commented 1 year ago

I read the README three times, but did not find anything that could relate to my case - error 409. Home Connect API documentation tell us - 409 - Command/Query cannot be executed for the home appliance, the error response contains the error details. How can I get text of response to determine what is happening? I have only one appliance.

What I tried to do: Register new application. Re-add Integration with new client_id, client_secret. Disable Integration for 12 hours. Checked that my Email does not contain capital letters.

ekutner commented 1 year ago

To see the error you should enable debug logging (see how in the README). However, you won't learn anything from this particular message. You're getting it because the integration sent too many API calls and was blocked. If you only have a single device this is most likely a problem with the device disconnecting/reconnecting to the wifi network too often. You can see some examples of this here #193 and here #127. If you are absolutely certain that this is not a wifi connectivity issue then please upload the debug log here and I'll take a look.

nordeep commented 1 year ago

I'm certain about that this is not a wifi issue. WiFi session of device is about 6 days long. HC connection status is always LOADED not BLOCKED. Nothing indicates that API requests are being exceeded.

Screenshot_17

home-assistant_2023-04-12-.log

nordeep commented 1 year ago

Android App is going to https://api-rus.home-connect.com/ for authorization. I tried to set api_host: https://api-rus.home-connect.com, unfortunately no luck. Stuck on another issue:

2023-04-12 17:30:32.026 DEBUG (MainThread) [home_connect_async.homeconnect] Exception in SSE event stream. Will wait for 2 seconds and retry
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 980, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore[return-value]  # noqa
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1076, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1060, in create_connection
    sock = await self._connect_sock(
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 969, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 501, in sock_connect
    return await fut
  File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 541, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
TimeoutError: [Errno 110] Connect call failed ('5.8.181.130', 80)

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

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/home_connect_async/homeconnect.py", line 248, in async_events_stream
    await event_source.connect()
  File "/usr/local/lib/python3.10/site-packages/aiohttp_sse_client/client.py", line 214, in connect
    response = await self._session.request(
  File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 536, in _request
    conn = await self._connector.connect(
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 540, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 901, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 1206, in _create_direct_connection
    raise last_exc
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 1175, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 988, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host api-rus.home-connect.com:80 ssl:default [Connect call failed ('5.8.181.130', 80)]
2023-04-12 17:30:34.037 DEBUG (MainThread) [aiohttp_sse_client.client] close
2023-04-12 17:30:34.037 DEBUG (MainThread) [home_connect_async.homeconnect] Connecting to SSE stream
2023-04-12 17:30:34.037 DEBUG (MainThread) [aiohttp_sse_client.client] connect

API does not respond to HTTP port, although the HTTPS is set.

ekutner commented 1 year ago

Don't do that, that parameter is only for China. I was wrong about the error code, the one I was referring to is 429, and I'm just so used to seeing it that I just saw your 409 as 429. Anyway, please add log_mode: 7 to the home_connect_alt configuration section in the configuration.yaml file and upload a new log file.

nordeep commented 1 year ago

Attached log with next config:

home_connect_alt:
  # HASS key
  client_id: !secret hc_client_id
  client_secret: !secret hc_client_secret
  #api_host: "https://api-rus.home-connect.com"
  log_mode: 7

home-assistant_2023-04-12--.log

ekutner commented 1 year ago

Thanks. Unfortunately this doesn't help because the SSE library I'm using doesn't provide the actual error message received with the 409 error code. I can make the following suggestions of things to try (in increasing order of complexity):

  1. If you have a home firewall that does any sort of URL filtering or HTTP manipulation, for example to block access to potentially risky domains, try to disable that.
  2. Completely remove the appliance from the Home Connect service and then add it back again. This has solved all sorts of weird issues for others.
  3. Use the API sand box here (https://api-docs.home-connect.com/#introduction), using Postman if you know how, to call the /homeappliances/events endpoint and see if you get the same error with more details.
  4. If you know how to do that then try installing Fiddler on your desktop computer and then configure it as proxy for HA so you can intercept the traffic and see the error response. You;ll also have to add the Fiddler root SSL certificate to the HA root certificates bundle. This is all quite complicated so I hope we won't get to that.

If none of these work I'll need you send me your credentials privately so I can test it my self, but hopefully we won't get to that.

ekutner commented 1 year ago

Closing for lack of progress