craibo / ha_strava

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

Detected that custom integration 'ha_strava' calls async_create_task from a thread at custom_components #153

Closed haaino closed 6 months ago

haaino commented 6 months ago

Hi,

I just installed HA 2024.5 and noticed a message in the logfile (see below). Hopefully this means something to someone.


Detected that custom integration 'ha_strava' calls async_create_task from a thread at custom_components/ha_strava/init.py, line 792: hass.async_create_task(strava_startup_functions()), please report it to the author of the 'ha_strava' custom integration


Best regards, Haaino

deifel commented 6 months ago

Same problem here since HA 2024.5

jouster1974 commented 6 months ago

same issue here...fine when winding back to 2024.4......thanks in advance for a fantastic integration

this has obviously caused some issues as all sensors are now unavailable

image

errors added for clarity

2024-05-02 09:42:12.253 WARNING (SyncWorker_21) [homeassistant.helpers.frame] Detected that custom integration 'ha_strava' calls async_create_task from a thread at custom_components/ha_strava/init.py, line 796: hass.async_create_task(strava_startup_functions()), please report it to the author of the 'ha_strava' custom integration File "/config/custom_components/ha_strava/init.py", line 796, in component_reload_handler hass.async_create_task(strava_startup_functions()) RuntimeError: Detected that custom integration 'ha_strava' calls async_create_task from a thread at custom_components/ha_strava/init.py, line 796: hass.async_create_task(strava_startup_functions()). Please report it to the author of the 'ha_strava' custom integration. 2024-05-02 09:42:12.306 WARNING (MainThread) [py.warnings] /usr/local/lib/python3.12/asyncio/base_events.py:1973: RuntimeWarning: coroutine 'async_setup_entry..strava_startup_functions' was never awaited 2024-05-02 09:44:05.839 WARNING (SyncWorker_39) [homeassistant.helpers.frame] Detected that custom integration 'ha_strava' calls async_create_task from a thread at custom_components/ha_strava/init.py, line 792: hass.async_create_task(strava_startup_functions()), please report it to the author of the 'ha_strava' custom integration 2024-05-02 09:45:10.567 WARNING (Recorder) [homeassistant.components.sensor.recorder] The unit of sensor.strava_stats_summary_ytd_run_moving_time (s) cannot be converted to the unit of previously compiled statistics (None). Generation of long term statistics will be suppressed unless the unit changes back to None or a compatible unit. Go to https://my.home-assistant.io/redirect/developer_statistics to fix this 2024-05-02 09:45:10.567 WARNING (Recorder) [homeassistant.components.sensor.recorder] The unit of sensor.strava_stats_summary_recent_ride_moving_time (s) cannot be converted to the unit of previously compiled statistics (None). Generation of long term statistics will be suppressed unless the unit changes back to None or a compatible unit. Go to https://my.home-assistant.io/redirect/developer_statistics to fix this 2024-05-02 09:45:10.567 WARNING (Recorder) [homeassistant.components.sensor.recorder] The unit of sensor.strava_stats_summary_recent_swim_moving_time (s) cannot be converted to the unit of previously compiled statistics (None). Generation of long term statistics will be suppressed unless the unit changes back to None or a compatible unit. Go to https://my.home-assistant.io/redirect/developer_statistics to fix this

craibo commented 6 months ago

Additional issues caused by ha core changing the logic to call methods via a thread instead of on the main process.

Detected that custom integration 'ha_strava' calls async_write_ha_state from a thread at custom_components/ha_strava/sensor.py, line 724: self.async_write_ha_state(), please report it to the author of the 'ha_strava' custom integration
Detected that custom integration 'ha_strava' calls async_write_ha_state from a thread at custom_components/ha_strava/sensor.py, line 340: self.async_write_ha_state(), please report it to the author of the 'ha_strava' custom integration
Logger: homeassistant
Source: helpers/frame.py:203
First occurred: 22:07:36 (91 occurrences)
Last logged: 22:07:37

Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/ha_strava/sensor.py", line 724, in strava_data_update_event_handler
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1008, in async_write_ha_state
    self.hass.verify_event_loop_thread("async_write_ha_state")
  File "/usr/src/homeassistant/homeassistant/core.py", line 440, in verify_event_loop_thread
    frame.report(
  File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 162, in report
    _report_integration(what, integration_frame, level, error_if_integration)
  File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 203, in _report_integration
    raise RuntimeError(
RuntimeError: Detected that custom integration 'ha_strava' calls async_write_ha_state from a thread at custom_components/ha_strava/sensor.py, line 724: self.async_write_ha_state(). Please report it to the author of the 'ha_strava' custom integration.
craibo commented 6 months ago

Unfortunately this issue is going to affect many custom integrations as there wasn't a heads up for the breaking change in HA Core.

Release 3.2.33 should resolve this issue

Thanks for the patience and support 👍🏻

jouster1974 commented 6 months ago

can confirm 3.2.33 has completely resolved the issue, thanks as always for your assistance and prompt fix....very much appeciated