Ver Fonte

device: use async_write_ha_state when in a thread

In many contexts we are always off the main thread, so do not need to
schedule the update for later, we can just write the state to the HA state
cache immediately.
Jason Rumney há 2 anos atrás
pai
commit
57218a3031
1 ficheiros alterados com 2 adições e 2 exclusões
  1. 2 2
      custom_components/tuya_local/device.py

+ 2 - 2
custom_components/tuya_local/device.py

@@ -212,7 +212,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_schedule_update_ha_state()
+                        entity.async_write_ha_state()
                 else:
                     _LOGGER.debug(
                         "%s received non data %s",
@@ -415,7 +415,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_schedule_update_ha_state()
+                entity.async_write_ha_state()
         _LOGGER.debug(
             "%s refreshed device state: %s",
             self.name,