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

Device comms: ensure errors get counted.

Errors were counted in retry_on_failed_connection, but error handling
in receive_loop is reporting warnings when error count is 0 (debug otherwise),
so obviously they have not been counted yet in that case. Make sure they do
get counted if detected at that level, but check against the previous error
count to ensure that they are not counted twice.

May prevent the frequent warnings reported in issue #3083 when devices are
offline long term.
Jason Rumney 10 месяцев назад
Родитель
Сommit
cece01d690
1 измененных файлов с 5 добавлено и 1 удалено
  1. 5 1
      custom_components/tuya_local/device.py

+ 5 - 1
custom_components/tuya_local/device.py

@@ -287,6 +287,7 @@ class TuyaLocalDevice(object):
             self._api.parent.set_socketPersistent(persist)
 
         while self._running:
+            error_count = self._api_working_protocol_failures
             try:
                 last_cache = self._cached_state.get("updated_at", 0)
                 now = time()
@@ -336,7 +337,10 @@ class TuyaLocalDevice(object):
 
                 if poll:
                     if "Error" in poll:
-                        if self._api_working_protocol_failures == 0:
+                        # increment the error count if not done already
+                        if error_count == self._api_working_protocol_failures:
+                            self._api_working_protocol_failures += 1
+                        if self._api_working_protocol_failures == 1:
                             _LOGGER.warning(
                                 "%s error reading: %s", self.name, poll["Error"]
                             )