Răsfoiți Sursa

fix(device): move initialisation of last_heartbeat outside the loop

We were reinitialising the last heartbeat time each time around the loop to the
last update time.
This can cause offsets in both directions;
 - for devices that only send updates on full polls, only the first heartbeat is
   delayed as designed, then the rest will come every 0.1s as before.
 - for devices that send frequent unsolicited messages, the heartbeat will get
   delayed, and this may cause timeouts.

High probability that he second case above is the cause of #4884 and #4885
Jason Rumney 2 luni în urmă
părinte
comite
ebe65c0c42
1 a modificat fișierele cu 1 adăugiri și 1 ștergeri
  1. 1 1
      custom_components/tuya_local/device.py

+ 1 - 1
custom_components/tuya_local/device.py

@@ -313,10 +313,10 @@ class TuyaLocalDevice(object):
         if self._api.parent:
         if self._api.parent:
             self._api.parent.set_socketPersistent(persist)
             self._api.parent.set_socketPersistent(persist)
 
 
+        last_heartbeat = self._cached_state.get("updated_at", 0)
         while self._running:
         while self._running:
             error_count = self._api_working_protocol_failures
             error_count = self._api_working_protocol_failures
             force_backoff = False
             force_backoff = False
-            last_heartbeat = self._cached_state.get("updated_at", 0)
             try:
             try:
                 await self._api_lock.acquire()
                 await self._api_lock.acquire()
                 last_cache = self._cached_state.get("updated_at", 0)
                 last_cache = self._cached_state.get("updated_at", 0)