Selaa lähdekoodia

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 17 tuntia sitten
vanhempi
commit
ca2c3dc66d
1 muutettua tiedostoa jossa 9 lisäystä ja 1 poistoa
  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
                     poll = None
 
 
                 if poll:
                 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
                         # increment the error count if not done already
                         if error_count == self._api_working_protocol_failures:
                         if error_count == self._api_working_protocol_failures:
                             self._api_working_protocol_failures += 1
                             self._api_working_protocol_failures += 1