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

Don't poll newly registered entities if the receive loop is running

When reloading entities and devices on a running HA instance, the receive
loop starts immediately, so we do not need to poll the device to get initial
state.  Doing so may clash with the receive loop and cause a transient
communication error.

Issue #443
Jason Rumney 3 лет назад
Родитель
Сommit
984db22350
1 измененных файлов с 4 добавлено и 3 удалено
  1. 4 3
      custom_components/tuya_local/device.py

+ 4 - 3
custom_components/tuya_local/device.py

@@ -151,9 +151,10 @@ class TuyaLocalDevice(object):
         self._refresh_task = None
 
     def register_entity(self, entity):
-        # If this is the first child entity to register, refresh the device
-        # state
-        should_poll = len(self._children) == 0
+        # If this is the first child entity to register, and HA is still
+        # starting, refresh the device state so it shows as available without
+        # waiting for startup to complete.
+        should_poll = len(self._children) == 0 and not self._hass.is_running
 
         self._children.append(entity)
         for dp in entity._config.dps():