Преглед на файлове

Mark async_actually_start as a callback.

async_actually_start was originally written to execute in the event
loop.  Since HA was modified to automatically run non-decorated
coroutines in the executor thread, this has been running in the wrong
thread, making some of its calls non-thread safe.

- Revert previous fix for #1871, #1872 (PR #1876), as it is not needed
when actually_start is running in the event loop, and has a side
effect of causing #1888 (a separate fix for that has been proposed on
the issue, but this revert also avoids that issue).

Issue #1917
Jason Rumney преди 1 година
родител
ревизия
7e0febcafa
променени са 1 файла, в които са добавени 3 реда и са изтрити 4 реда
  1. 3 4
      custom_components/tuya_local/device.py

+ 3 - 4
custom_components/tuya_local/device.py

@@ -14,7 +14,7 @@ from homeassistant.const import (
     EVENT_HOMEASSISTANT_STARTED,
     EVENT_HOMEASSISTANT_STOP,
 )
-from homeassistant.core import HomeAssistant
+from homeassistant.core import HomeAssistant, callback
 
 from .const import (
     API_PROTOCOL_VERSIONS,
@@ -138,15 +138,14 @@ class TuyaLocalDevice(object):
         """Return True if the device has returned some state."""
         return len(self._get_cached_state()) > 1
 
+    @callback
     def actually_start(self, event=None):
         _LOGGER.debug("Starting monitor loop for %s", self.name)
         self._running = True
         self._shutdown_listener = self._hass.bus.async_listen_once(
             EVENT_HOMEASSISTANT_STOP, self.async_stop
         )
-        self._refresh_task = asyncio.run_coroutine_threadsafe(
-            self.receive_loop(), self._hass.loop
-        )
+        self._refresh_task = self._hass.async_create_task(self.receive_loop())
 
     def start(self):
         if self._hass.is_stopping: