Jelajahi Sumber

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 2 minggu lalu
induk
melakukan
0ecabd0fff
1 mengubah file dengan 2 tambahan dan 0 penghapusan
  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):
     def decode_value(self, v, device):
         if self.rawtype == "hex" and isinstance(v, str):
         if self.rawtype == "hex" and isinstance(v, str):
             try:
             try:
+                if (len(v) % 2) != 0:
+                    v = "0" + v
                 return bytes.fromhex(v)
                 return bytes.fromhex(v)
             except ValueError:
             except ValueError:
                 _LOGGER.warning(
                 _LOGGER.warning(