Parcourir la source

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 il y a 3 ans
Parent
commit
984db22350
1 fichiers modifiés avec 4 ajouts et 3 suppressions
  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
         self._refresh_task = None
 
 
     def register_entity(self, entity):
     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)
         self._children.append(entity)
         for dp in entity._config.dps():
         for dp in entity._config.dps():