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

fix(device): handle error responses as exceptions

Since some tinytuya versions ago, connection errors are no longer raised
as exceptions and instead returned as Error responses.

We were logging these, but not doing any other error handling on the connection.

- disconnect the socket to allow a better chance of recovery from low level problems
- backoff for a period to allow the device time to recover

Issue #5985
Jason Rumney 14 часов назад
Родитель
Сommit
ca2c3dc66d
1 измененных файлов с 9 добавлено и 1 удалено
  1. 9 1
      custom_components/tuya_local/device.py

+ 9 - 1
custom_components/tuya_local/device.py

@@ -406,7 +406,15 @@ class TuyaLocalDevice(object):
                     poll = None
 
                 if poll:
-                    if "Error" in poll:
+                    if "Err" in poll:
+                        # Limit disconnects to the errors that are caused low level
+                        # communication problems
+                        if poll["Err"] in {"901", "902", "905", "906", "914"}:
+                            force_backoff = True
+                            persist = False
+                            self._api.set_socketPersistent(False)
+                            if self._api.parent:
+                                self._api.parent.set_socketPersistent(False)
                         # increment the error count if not done already
                         if error_count == self._api_working_protocol_failures:
                             self._api_working_protocol_failures += 1