Home Connect (BSH) - Client Error: Too Many Requests

Hi,

since a week or so the BSH Home Connect integration has started to have a connection issue:

Logger: homeassistant.config_entries
Source: config_entries.py:406
First occurred: January 20, 2024 at 14:00:13 (4 occurrences)
Last logged: 14:00:22

Error setting up entry Diskmaskin for home_connect
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/homeconnect/sseclient.py", line 62, in _connect
    self.resp.raise_for_status()
  File "/usr/local/lib/python3.11/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 429 Client Error: Too Many Requests for url: https://api.home-connect.com/api/homeappliances/events

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 406, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/home_connect/__init__.py", line 284, in async_setup_entry
    await update_all_devices(hass, entry)
  File "/usr/src/homeassistant/homeassistant/components/home_connect/__init__.py", line 322, in update_all_devices
    await hass.async_add_executor_job(device.initialize)
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/home_connect/api.py", line 138, in initialize
    self.appliance.listen_events(callback=self.event_callback)
  File "/usr/local/lib/python3.11/site-packages/homeconnect/api.py", line 305, in listen_events
    self.hc.listen_events()
  File "/usr/local/lib/python3.11/site-packages/homeconnect/api.py", line 161, in listen_events
    sse = SSEClient(uri, session=self._oauth, retry=1000, timeout=TIMEOUT_S)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/homeconnect/sseclient.py", line 47, in __init__
    self._connect()
  File "/usr/local/lib/python3.11/site-packages/homeconnect/sseclient.py", line 67, in _connect
    self._connect()
  File "/usr/local/lib/python3.11/site-packages/homeconnect/sseclient.py", line 56, in _connect
    self.resp = requester.get(self.url, stream=True, **self.requests_kwargs)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/requests/sessions.py", line 602, in get
    return self.request("GET", url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/requests_oauthlib/oauth2_session.py", line 483, in request
    url, headers, data = self._client.add_token(
                         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/oauthlib/oauth2/rfc6749/clients/base.py", line 217, in add_token
    raise TokenExpiredError()
oauthlib.oauth2.rfc6749.errors.TokenExpiredError: (token_expired) 

As far as I know there has not been any change on my side in the last week. Or any change at all for that matter.

image
If I manually reload the integration it usually becomes active, but then the next day it is in failed mode again.

The first question is how to understand why I’m hitting the request limit (and what is the limit?).

I’m not saying I had the same problems, but I had plenty. I have switched to Home Connect Alt, and now I have fewer problems - but not none. My dishwasher seems to go unavailable multiple times during the day, and if it stays unavailable for over about 10 minutes, it will not come back unless I reload the integration, which I have automated. Similarly, when I start the dishwasher I have to include retries and error handling for it to reliably work.

I’ll have a look at the alnternate intgration, in the meanwhile I have re-written my integration reloader automation to better(?) handle the need for when to reload.