瀏覽代碼

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 4 月之前
父節點
當前提交
0ecabd0fff
共有 1 個文件被更改,包括 2 次插入 和 0 次删除
  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(