Quellcode durchsuchen

fix(masked hex): if length is odd, prefix a 0 before decoding

Python fromHex() requires an even number of hex digits.

If Tuya devices expect an odd number on input, then more changes will
be needed, but for now the only use case is a read-only field with
9 flags as ASCII 0 or 1 which we decoded as hex to reuse existing
mask functionality.

Issue #5208
Jason Rumney vor 4 Monaten
Ursprung
Commit
0ecabd0fff
1 geänderte Dateien mit 2 neuen und 0 gelöschten Zeilen
  1. 2 0
      custom_components/tuya_local/helpers/device_config.py

+ 2 - 0
custom_components/tuya_local/helpers/device_config.py

@@ -513,6 +513,8 @@ class TuyaDpsConfig:
     def decode_value(self, v, device):
         if self.rawtype == "hex" and isinstance(v, str):
             try:
+                if (len(v) % 2) != 0:
+                    v = "0" + v
                 return bytes.fromhex(v)
             except ValueError:
                 _LOGGER.warning(