Просмотр исходного кода

HA 2024.5.0 Issue fixes
- Attempt to resolve coroutine issues

craibo 1 год назад
Родитель
Сommit
9fe774e52f

+ 5 - 3
custom_components/tuya_local/device.py

@@ -144,7 +144,9 @@ class TuyaLocalDevice(object):
         self._shutdown_listener = self._hass.bus.async_listen_once(
             EVENT_HOMEASSISTANT_STOP, self.async_stop
         )
-        self._refresh_task = self._hass.async_create_task(self.receive_loop())
+        self._refresh_task = asyncio.run_coroutine_threadsafe(
+            self.receive_loop(), self._hass.loop
+        )
 
     def start(self):
         if self._hass.is_stopping:
@@ -215,7 +217,7 @@ class TuyaLocalDevice(object):
                             for dp in entity._config.dps():
                                 if not dp.persist and dp.id not in poll:
                                     self._cached_state.pop(dp.id, None)
-                        entity.async_write_ha_state()
+                        entity.schedule_update_ha_state()
                 else:
                     _LOGGER.debug(
                         "%s received non data %s",
@@ -421,7 +423,7 @@ class TuyaLocalDevice(object):
                     # Clear non-persistant dps that were not in the poll
                     if not dp.persist and dp.id not in new_state.get("dps", {}):
                         self._cached_state.pop(dp.id, None)
-                entity.async_write_ha_state()
+                entity.schedule_update_ha_state()
         _LOGGER.debug(
             "%s refreshed device state: %s",
             self.name,

+ 1 - 1
custom_components/tuya_local/manifest.json

@@ -13,5 +13,5 @@
     "requirements": [
         "tinytuya==1.13.2"
     ],
-    "version": "2024.5.1"
+    "version": "2024.5.2"
 }