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

HA 2024.5 hotfix: do not call async_write_ha_state from receive thread

HA has gone from silence straight to preventing the integration working
when async_write_ha_state is used from the receive thread.
Instead we need to schedule an update, and make the update not poll
when the receive loop is running.

Issue #1869
Jason Rumney 1 год назад
Родитель
Сommit
527e28ddd3
1 измененных файлов с 6 добавлено и 5 удалено
  1. 6 5
      custom_components/tuya_local/device.py

+ 6 - 5
custom_components/tuya_local/device.py

@@ -215,7 +215,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",
@@ -382,10 +382,11 @@ class TuyaLocalDevice(object):
 
     async def async_refresh(self):
         _LOGGER.debug("Refreshing device state for %s", self.name)
-        await self._retry_on_failed_connection(
-            lambda: self._refresh_cached_state(),
-            f"Failed to refresh device state for {self.name}.",
-        )
+        if self.should_poll:
+            await self._retry_on_failed_connection(
+                lambda: self._refresh_cached_state(),
+                f"Failed to refresh device state for {self.name}.",
+            )
 
     def get_property(self, dps_id):
         cached_state = self._get_cached_state()