Browse Source

fix(device): catch BaseException instead of Exception

Only user defined exceptions are subclasses of Exception in Python.
But HA prefers to use built-in exception types for the exceptions it throws,
in particular ValueError is thrown during processing of enum sensor values
when unexpected values are thrown, which was causing the receive loop to
terminate since we were not catching it.

Mentioned in comment on #2581, probably a root cause of #5848
Jason Rumney 7 giờ trước cách đây
mục cha
commit
4fc87267e5
1 tập tin đã thay đổi với 6 bổ sung và 5 xóa
  1. 6 5
      custom_components/tuya_local/device.py

+ 6 - 5
custom_components/tuya_local/device.py

@@ -125,7 +125,7 @@ class TuyaLocalDevice(object):
                             "tuyadevice": self._api,
                             "tuyadevicelock": self._api_lock,
                         }
-        except Exception as e:
+        except BaseException as e:
             _LOGGER.error(
                 "%s: %s while initialising device %s",
                 type(e).__name__,
@@ -277,7 +277,7 @@ class TuyaLocalDevice(object):
                         # let entities trigger off poll contents directly
                         try:
                             entity.on_receive(poll, full_poll)
-                        except Exception as e:
+                        except BaseException as e:
                             # Don't let exceptions thrown by the entities interrupt the communication loop
                             # Just log them and move on.
                             _LOGGER.exception(
@@ -286,6 +286,7 @@ class TuyaLocalDevice(object):
                                 entity.entity_id,
                                 e,
                             )
+
                         # clear non-persistant dps that were not in a full poll
                         if full_poll:
                             for dp in entity._config.dps():
@@ -300,7 +301,7 @@ class TuyaLocalDevice(object):
                     )
             _LOGGER.warning("%s receive loop has terminated", self.name)
 
-        except Exception as t:
+        except BaseException as t:
             _LOGGER.exception(
                 "%s receive loop terminated by exception %s", self.name, t
             )
@@ -448,7 +449,7 @@ class TuyaLocalDevice(object):
                 if self._api.parent:
                     self._api.parent.set_socketPersistent(False)
                 raise
-            except Exception as t:
+            except BaseException as t:
                 _LOGGER.exception(
                     "%s receive loop error %s:%s",
                     self.name,
@@ -705,7 +706,7 @@ class TuyaLocalDevice(object):
                     self._api_protocol_working = True
                     self._api_working_protocol_failures = 0
                     return retval
-            except Exception as e:
+            except BaseException as e:
                 _LOGGER.debug(
                     "Retrying after exception %s %s (%d/%d)",
                     type(e).__name__,