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

Device: make error reporting less verbose

- If we are already in a non-communicative state, report communication
errors as debug messages rather than warnings.
- lower some frequently reported messages from info to debug.
Jason Rumney 1 год назад
Родитель
Сommit
01fc484e2a
1 измененных файлов с 25 добавлено и 12 удалено
  1. 25 12
      custom_components/tuya_local/device.py

+ 25 - 12
custom_components/tuya_local/device.py

@@ -333,11 +333,16 @@ class TuyaLocalDevice(object):
 
                 if poll:
                     if "Error" in poll:
-                        _LOGGER.warning(
-                            "%s error reading: %s", self.name, poll["Error"]
-                        )
+                        if self._api_working_protocol_failures == 0:
+                            _LOGGER.warning(
+                                "%s error reading: %s", self.name, poll["Error"]
+                            )
+                        else:
+                            _LOGGER.debug(
+                                "%s error reading: %s", self.name, poll["Error"]
+                            )
                         if "Payload" in poll and poll["Payload"]:
-                            _LOGGER.info(
+                            _LOGGER.debug(
                                 "%s err payload: %s",
                                 self.name,
                                 poll["Payload"],
@@ -481,12 +486,20 @@ class TuyaLocalDevice(object):
             log_json(new_state),
         )
         if "Err" in new_state:
-            _LOGGER.warning(
-                "%s protocol error %s: %s",
-                self.name,
-                new_state.get("Err"),
-                new_state.get("Error", "message not provided"),
-            )
+            if self._api_working_protocol_failures == 1:
+                _LOGGER.warning(
+                    "%s protocol error %s: %s",
+                    self.name,
+                    new_state.get("Err"),
+                    new_state.get("Error", "message not provided"),
+                )
+            else:
+                _LOGGER.debug(
+                    "%s protocol error %s: %s",
+                    self.name,
+                    new_state.get("Err"),
+                    new_state.get("Error", "message not provided"),
+                )
         _LOGGER.debug(
             "new state (incl pending): %s",
             log_json(self._get_cached_state()),
@@ -608,7 +621,7 @@ class TuyaLocalDevice(object):
                     if self._api_working_protocol_failures == 1:
                         _LOGGER.error(error_message)
                     else:
-                        _LOGGER.info(error_message)
+                        _LOGGER.debug(error_message)
 
                 if not self._api_protocol_working:
                     await self._rotate_api_protocol_version()
@@ -661,7 +674,7 @@ class TuyaLocalDevice(object):
             self._api_protocol_version_index = 0
 
         new_version = API_PROTOCOL_VERSIONS[self._api_protocol_version_index]
-        _LOGGER.info(
+        _LOGGER.debug(
             "Setting protocol version for %s to %0.1f",
             self.name,
             new_version,