Ver código fonte

fix (masked values): provide better error message when setting fails

We cannot set a masked value without knowing the current value to mask against.
Instead of letting Python raise a generic exception about the None value,
raise a specific message that is easier for the user to understand.

Issue #4473
Jason Rumney 5 dias atrás
pai
commit
4a6f2a7ca3

+ 3 - 1
custom_components/tuya_local/helpers/device_config.py

@@ -1067,7 +1067,9 @@ class TuyaDpsConfig:
             else:
                 decoded_value = self.decode_value(raw_current, device)
 
-            if isinstance(decoded_value, int):
+            if decoded_value is None:
+                raise ValueError(f"Cannot mask unknown current value")
+            elif isinstance(decoded_value, int):
                 current_value = decoded_value
                 result = (current_value & ~mask) | (mask & int(result * mask_scale))
                 # Only convert back to bytes if the DP is actually hex/base64