浏览代码

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 周之前
父节点
当前提交
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):
         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(