Просмотр исходного кода

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 недель назад
Родитель
Сommit
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(