Преглед изворни кода

Update device_config.py for mask_signed: True

Changed mask_signed: True and count the number of bits in the mask
BevDan пре 8 месеци
родитељ
комит
ac47d54f51
1 измењених фајлова са 5 додато и 4 уклоњено
  1. 5 4
      custom_components/tuya_local/helpers/device_config.py

+ 5 - 4
custom_components/tuya_local/helpers/device_config.py

@@ -483,10 +483,11 @@ class TuyaDpsConfig:
             raw_result = (value & mask) // scale
 
             # Insert signed interpretation here
-            signed_bits = self._config.get("signed_bits")
-            if signed_bits:
-                raw_result = to_signed(raw_result, signed_bits)
-
+            if self._config.get("mask_signed", False):
+            # Count how many bits are set in the mask
+                bit_count = bin(mask).count("1")
+                raw_result = to_signed(raw_result, bit_count)
+    
             return self._map_from_dps(raw_result, device)
         else:
             return self._map_from_dps(device.get_property(self.id), device)