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

Round to int when checking if value is in range.

If we compare as float, it is detected as out of range when
setting 33% for a 1 - 3 range option, due to the calculated
but not yet rounded value being 0.99.

Issue #1014
Jason Rumney 2 лет назад
Родитель
Сommit
48573f88ba
1 измененных файлов с 2 добавлено и 2 удалено
  1. 2 2
      custom_components/tuya_local/helpers/device_config.py

+ 2 - 2
custom_components/tuya_local/helpers/device_config.py

@@ -44,7 +44,7 @@ def _scale_range(r, s):
     "Scale range r by factor s"
     if s == 1:
         return r
-    return {"min": r["min"] / s, "max": r["max"] / s}
+    return {"min": int(r["min"] / s), "max": int(r["max"] / s)}
 
 
 _unsigned_fmts = {
@@ -894,7 +894,7 @@ class TuyaDpsConfig:
         if r and isinstance(result, Number):
             mn = r["min"]
             mx = r["max"]
-            if result < mn or result > mx:
+            if round(result) < mn or round(result) > mx:
                 # Output scaled values in the error message
                 r = self.range(device, scaled=True)
                 mn = r["min"]