craibo / ha_strava

Strava Activities and Summary data integration for Home Assistant
MIT License
78 stars 9 forks source link

Need to restart HA to get Strava sensors updates #152

Closed bckthomas closed 6 months ago

bckthomas commented 7 months ago

Hi

I get this error in the logs when Strava wants to update : Expected 1 webhook subscription for https://homeassistant.xxx.fr/api/strava/webhook; found: 0

The callback is configured with the correct domain :

image

On restart, despite this error, my last activity is displayed in sensor.strava_0_0 Unexpected response (status code: 400) while creating Strava Webhook Subscription: {"message":"Bad Request","errors":[{"resource":"PushSubscription","field":"callback url","code":"GET to callback URL does not return 200"}]}

Strava 3.2.32 Core 2024.4.2 Supervisor 2024.04.0 Operating System 12.1

jacme31 commented 7 months ago

I have the same error in the logs concerning the webhook subscriptionand all my strava.sensors remain unavailable even after a restart. Same configuration : Core 2024.4.2 Supervisor 2024.04.0 Operating System 12.1 Strava 3.2.32

craibo commented 7 months ago

Hi @jacme31 , @bckthomas

I have not been able to replicate this issue locally.

Are you able to

  1. Enable debug mode for Strava device (Settings --> Devices & services --> Strava (Unofficial) --> Enable debug bottom left)
  2. Replicate the issue
  3. Share the debug log here for me to review

?

Thank you

bckthomas commented 7 months ago

Hi @craibo Here is the log error:

2024-04-10 08:33:32.114 ERROR (MainThread) [homeassistant.config_entries] Error unloading entry Strava for ha_strava
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 724, in async_unload
    result = await component.async_unload_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/ha_strava/__init__.py", line 867, in async_unload_entry
    remove_listener()
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 844, in <lambda>
    return lambda: self.update_listeners.remove(listener)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: list.remove(x): x not in list
jacme31 commented 7 months ago

In my case, I found out the reason for the problem. The "homeassistant external URL" setting (Settings > System > Network) was incorrect. (I had positioned port 8123 even though I use a reverse proxy and internet communication is done on port 443). What is strange is that this configuration error is very old and had not caused any problem before the latest updates of HA core and Strava. After correction STRAVA Integration works perfectly and sorry for the inconvenience.

For information and if it helps I had the same log as @bckthomas when reloading the integration. On the other hand, when restarting Home Assistant I found this error in the logs

Traceback (most recent call last):
   File "/config/custom_components/ha_strava/__init__.py", line 781, in strava_startup_functions
     await renew_webhook_subscription(
   File "/config/custom_components/ha_strava/__init__.py", line 630, in renew_webhook_subscription
     callback_response = await websession.get(url=config_data[CONF_CALLBACK_URL])
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^
   File "/usr/local/lib/python3.12/site-packages/aiohttp/client.py", line 578, 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 911, in _create_connection
     _, proto = await self._create_direct_connection(req, traces, timeout)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^
   File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1235, in _create_direct_connection
     raise last_exc
   File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1204, in _create_direct_connection
     transp, proto = await self._wrap_create_connection(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1000, in _wrap_create_connection
     raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host HAhost.mydomain.fr:8123 ssl:default [Connect call failed ('99.99.99.99', 8123)]
craibo commented 7 months ago

Thanks @jacme31, glad its working for you. That would explain the other issues you saw similar to @bckthomas's

@bckthomas I believe the errors you have shared are a result of the original webhook listener setup failing. There should be another error similar to @jacme31's one pointing us in the right direction to solve this.

bckthomas commented 7 months ago

Hi everyone

I think the external url is correctly configured for me

image

Can anyone give me a lead on how to investigate the original webhook listener?

bckthomas commented 7 months ago

Hi @craibo, @jacme31

In core.config_entries file, the callback_url is "https://homeassistant.xxx.fr/api/strava/webhook". is this good or should it be my.home-assistant.io ?

craibo commented 7 months ago

Hi @bckthomas

The url looks correct.

Can you please:

  1. Navigate to Settings -> Devices & services
  2. Find Strava (Unofficial) and click on it
  3. Click Enable Debug Logging bottom left
  4. Click the 3 dots on the right of the integration entries and select reload
  5. Navigate to Settings -> System -> Logs
  6. Scroll to the bottom and select Load Full Logs
  7. Search for _hastrava
  8. Share those with us please, look for an Red ERROR messages. Hopefully they will contain the issue

EDIT:

  1. After the reload completes.
  2. Stop the Debug Logging
  3. This should provide a downloadable log file. Please share this
bckthomas commented 7 months ago

Hi

This is the error in log

2024-04-12 09:02:56.804 ERROR (MainThread) [custom_components.ha_strava] Expected 1 webhook subscription for https://homeassistant.xxx.fr/api/strava/webhook; found: 0