plugwise / plugwise_usb-beta

Custom-component / development version of the USB Plugwise Home Assistant platform
MIT License
4 stars 4 forks source link

[BUG]: Warnings in HA log about threading #148

Open mvdwetering opened 3 months ago

mvdwetering commented 3 months ago

Describe the bug.

I noticed the following sets of warnings in my HA logs. These kind of warnings are new in HA 2024.5.0.

I am not entirely sure what exactly triggered it, but I just re-enabled this integration after some downtime of my system. For some reason they did not show up when connecting to the same stick on my dev setup.

Logger: py.warnings
Bron: /usr/local/lib/python3.12/warnings.py:110
Eerst voorgekomen: 14:14:01 (9 gebeurtenissen)
Laatst gelogd: 14:18:25

/usr/local/lib/python3.12/site-packages/plugwise_usb/__init__.py:680: RuntimeWarning: coroutine 'async_setup_entry.<locals>.async_add_binary_sensors' was never awaited _LOGGER.error("Error while executing callback : %s", err)
/usr/local/lib/python3.12/site-packages/plugwise_usb/__init__.py:680: RuntimeWarning: coroutine 'async_setup_entry.<locals>.async_add_sensors' was never awaited _LOGGER.error("Error while executing callback : %s", err)
/usr/local/lib/python3.12/site-packages/plugwise_usb/__init__.py:680: RuntimeWarning: coroutine 'async_setup_entry.<locals>.async_add_switches' was never awaited _LOGGER.error("Error while executing callback : %s", err)
Logger: plugwise_usb
Bron: /usr/local/lib/python3.12/site-packages/plugwise_usb/__init__.py:680
Eerst voorgekomen: 14:14:01 (24 gebeurtenissen)
Laatst gelogd: 14:18:25

Error while executing callback : Detected that custom integration 'plugwise_usb' calls async_create_task from a thread at custom_components/plugwise_usb/binary_sensor.py, line 84: hass.async_create_task(async_add_binary_sensors(mac)). Please report it to the author of the 'plugwise_usb' custom integration.
Error while executing callback : Detected that custom integration 'plugwise_usb' calls async_create_task from a thread at custom_components/plugwise_usb/sensor.py, line 44: hass.async_create_task(async_add_sensors(mac)). Please report it to the author of the 'plugwise_usb' custom integration.
Error while executing callback : Detected that custom integration 'plugwise_usb' calls async_create_task from a thread at custom_components/plugwise_usb/switch.py, line 42: hass.async_create_task(async_add_switches(mac)). Please report it to the author of the 'plugwise_usb' custom integration.

What version of Plugwise Beta are you using?

v0.40.7

What was the last working version of Plugwise Beta (or Core if not using beta before)?

No response

What version of Home Assistant Core are you using?

2024.5.2

What type of installation are you running?

Home Assistant OS

How did you install plugwise-beta?

HACS

What kind of Plugwise device is having issues?

USB: Stick

What firmware version is your Plugwise product at?

Circle+ 2011-06-27 10:47:37, Circle 2011-06-27 10:52:18, 8x Circle 2009-09-08 15:50:31

Logging

2024-05-09 14:18:25.739 WARNING (serial_reader_thread) [homeassistant.helpers.frame] Detected that custom integration 'plugwise_usb' calls async_create_task from a thread at custom_components/plugwise_usb/binary_sensor.py, line 84: hass.async_create_task(async_add_binary_sensors(mac)), please report it to the author of the 'plugwise_usb' custom integration 2024-05-09 14:18:25.739 ERROR (serial_reader_thread) [plugwise_usb] Error while executing callback : Detected that custom integration 'plugwise_usb' calls async_create_task from a thread at custom_components/plugwise_usb/binary_sensor.py, line 84: hass.async_create_task(async_add_binary_sensors(mac)). Please report it to the author of the 'plugwise_usb' custom integration. 2024-05-09 14:18:25.739 WARNING (serial_reader_thread) [py.warnings] /usr/local/lib/python3.12/site-packages/plugwise_usb/init.py:680: RuntimeWarning: coroutine 'async_setup_entry..async_add_binary_sensors' was never awaited _LOGGER.error("Error while executing callback : %s", err) 2024-05-09 14:18:25.742 WARNING (serial_reader_thread) [homeassistant.helpers.frame] Detected that custom integration 'plugwise_usb' calls async_create_task from a thread at custom_components/plugwise_usb/sensor.py, line 44: hass.async_create_task(async_add_sensors(mac)), please report it to the author of the 'plugwise_usb' custom integration 2024-05-09 14:18:25.742 ERROR (serial_reader_thread) [plugwise_usb] Error while executing callback : Detected that custom integration 'plugwise_usb' calls async_create_task from a thread at custom_components/plugwise_usb/sensor.py, line 44: hass.async_create_task(async_add_sensors(mac)). Please report it to the author of the 'plugwise_usb' custom integration. 2024-05-09 14:18:25.742 WARNING (serial_reader_thread) [py.warnings] /usr/local/lib/python3.12/site-packages/plugwise_usb/init.py:680: RuntimeWarning: coroutine 'async_setup_entry..async_add_sensors' was never awaited _LOGGER.error("Error while executing callback : %s", err) 2024-05-09 14:18:25.744 WARNING (serial_reader_thread) [homeassistant.helpers.frame] Detected that custom integration 'plugwise_usb' calls async_create_task from a thread at custom_components/plugwise_usb/switch.py, line 42: hass.async_create_task(async_add_switches(mac)), please report it to the author of the 'plugwise_usb' custom integration 2024-05-09 14:18:25.744 ERROR (serial_reader_thread) [plugwise_usb] Error while executing callback : Detected that custom integration 'plugwise_usb' calls async_create_task from a thread at custom_components/plugwise_usb/switch.py, line 42: hass.async_create_task(async_add_switches(mac)). Please report it to the author of the 'plugwise_usb' custom integration. 2024-05-09 14:18:25.744 WARNING (serial_reader_thread) [py.warnings] /usr/local/lib/python3.12/site-packages/plugwise_usb/init.py:680: RuntimeWarning: coroutine 'async_setup_entry..async_add_switches' was never awaited _LOGGER.error("Error while executing callback : %s", err) 2024-05-09 14:18:25.850 WARNING (serial_reader_thread) [homeassistant.helpers.frame] Detected that custom integration 'plugwise_usb' calls async_create_task from a thread at custom_components/plugwise_usb/binary_sensor.py, line 84: hass.async_create_task(async_add_binary_sensors(mac)), please report it to the author of the 'plugwise_usb' custom integration 2024-05-09 14:18:25.850 ERROR (serial_reader_thread) [plugwise_usb] Error while executing callback : Detected that custom integration 'plugwise_usb' calls async_create_task from a thread at custom_components/plugwise_usb/binary_sensor.py, line 84: hass.async_create_task(async_add_binary_sensors(mac)). Please report it to the author of the 'plugwise_usb' custom integration. 2024-05-09 14:18:25.853 WARNING (serial_reader_thread) [homeassistant.helpers.frame] Detected that custom integration 'plugwise_usb' calls async_create_task from a thread at custom_components/plugwise_usb/sensor.py, line 44: hass.async_create_task(async_add_sensors(mac)), please report it to the author of the 'plugwise_usb' custom integration 2024-05-09 14:18:25.853 ERROR (serial_reader_thread) [plugwise_usb] Error while executing callback : Detected that custom integration 'plugwise_usb' calls async_create_task from a thread at custom_components/plugwise_usb/sensor.py, line 44: hass.async_create_task(async_add_sensors(mac)). Please report it to the author of the 'plugwise_usb' custom integration. 2024-05-09 14:18:25.855 WARNING (serial_reader_thread) [homeassistant.helpers.frame] Detected that custom integration 'plugwise_usb' calls async_create_task from a thread at custom_components/plugwise_usb/switch.py, line 42: hass.async_create_task(async_add_switches(mac)), please report it to the author of the 'plugwise_usb' custom integration 2024-05-09 14:18:25.855 ERROR (serial_reader_thread) [plugwise_usb] Error while executing callback : Detected that custom integration 'plugwise_usb' calls async_create_task from a thread at custom_components/plugwise_usb/switch.py, line 42: hass.async_create_task(async_add_switches(mac)). Please report it to the author of the 'plugwise_usb' custom integration. 2024-05-09 14:18:25.992 WARNING (serial_reader_thread) [homeassistant.helpers.frame] Detected that custom integration 'plugwise_usb' calls async_create_task from a thread at custom_components/plugwise_usb/binary_sensor.py, line 84: hass.async_create_task(async_add_binary_sensors(mac)), please report it to the author of the 'plugwise_usb' custom integration 2024-05-09 14:18:25.992 ERROR (serial_reader_thread) [plugwise_usb] Error while executing callback : Detected that custom integration 'plugwise_usb' calls async_create_task from a thread at custom_components/plugwise_usb/binary_sensor.py, line 84: hass.async_create_task(async_add_binary_sensors(mac)). Please report it to the author of the 'plugwise_usb' custom integration. 2024-05-09 14:18:25.995 WARNING (serial_reader_thread) [homeassistant.helpers.frame] Detected that custom integration 'plugwise_usb' calls async_create_task from a thread at custom_components/plugwise_usb/sensor.py, line 44: hass.async_create_task(async_add_sensors(mac)), please report it to the author of the 'plugwise_usb' custom integration 2024-05-09 14:18:25.995 ERROR (serial_reader_thread) [plugwise_usb] Error while executing callback : Detected that custom integration 'plugwise_usb' calls async_create_task from a thread at custom_components/plugwise_usb/sensor.py, line 44: hass.async_create_task(async_add_sensors(mac)). Please report it to the author of the 'plugwise_usb' custom integration. 2024-05-09 14:18:25.998 WARNING (serial_reader_thread) [homeassistant.helpers.frame] Detected that custom integration 'plugwise_usb' calls async_create_task from a thread at custom_components/plugwise_usb/switch.py, line 42: hass.async_create_task(async_add_switches(mac)), please report it to the author of the 'plugwise_usb' custom integration 2024-05-09 14:18:25.998 ERROR (serial_reader_thread) [plugwise_usb] Error while executing callback : Detected that custom integration 'plugwise_usb' calls async_create_task from a thread at custom_components/plugwise_usb/switch.py, line 42: hass.async_create_task(async_add_switches(mac)). Please report it to the author of the 'plugwise_usb' custom integration.

Diagnostics information

No diagnostics option

Additional information

I have been looking through the code a bit and I noticed that the discovered_device callback methods are calling hass.async_create_task.

According to https://developers.home-assistant.io/docs/asyncio_working_with_async this is used for starting tasks from async. However I think the stick api (python-plugwise-usb) is using threading, so the discovered_device device callback is probably called from a thread? That also seems to match with what the warnings are saying.

I would guess that instead something like below should/could be done? However I am a bit worried that this could block the thread for a while, so would like a second opinion before trying this out on my setup.

    def discovered_device(mac: str):
        """Add switches for newly discovered device."""
        asyncio.run_coroutine_threadsafe(async_add_switches(mac), hass.loop).result()