make-all / tuya-local

Local support for Tuya devices in Home Assistant
MIT License
1.07k stars 432 forks source link

"Auto" IP address setting results in a sleep on the event loop thread #407

Closed make-all closed 3 weeks ago

make-all commented 1 year ago

Describe the bug When IP address is set to "Auto", the tinytuya library does device discovery in background, and sleeps until the result comes back. Since tinytuya is not async this sleep blocks the event loop.

To Reproduce

  1. Add a new device, setting the IP address to "Auto".
  2. Look in the log for HA complaining that this integration is blocking the event loop by doing a sleep.

Expected behavior Ideally we should be a good HA citizen and not block other integrations or HA core from running.

Additional context

Logger: homeassistant.util.async_
Source: util/async_.py:182
First occurred: 11:09:29 (2 occurrences)
Last logged: 11:09:54

Detected blocking call to sleep inside the event loop. This is causing stability issues. Please report issue to the custom integration author for tuya_local doing blocking calls at custom_components/tuya_local/device.py, line 69: self._api = tinytuya.Device(dev_id, address, local_key)
Oglaf commented 1 year ago

Thank you! I didn't understand the message error until you explained it, I already had static IP address for my Tuya devices but I was lazy and used auto anyway. After changing to use IP address seems like the warnings are gone.

Vitani commented 1 month ago

Looks like a good way to reproduce this is to set up a device, make sure it works, and then turn it off. My HA appears to become completely unresponsive every minute or so while the "sleep" is taking place (disabling the integration for that device resolves the issue)