Browse Source

feat(number): allow max and min dps to be optional

Fall back on using the range of the value dp when maximum and minimum
are configured, but not reported by the device.

For implementation of idea in discussion #3373
Jason Rumney 9 tháng trước cách đây
mục cha
commit
36cda0a3b1

+ 6 - 2
custom_components/tuya_local/number.py

@@ -70,14 +70,18 @@ class TuyaLocalNumber(TuyaLocalEntity, NumberEntity):
     @property
     @property
     def native_min_value(self):
     def native_min_value(self):
         if self._min_dps is not None:
         if self._min_dps is not None:
-            return self._min_dps.get_value(self._device)
+            minimum = self._min_dps.get_value(self._device)
+            if minimum is not None:
+                return minimum
         r = self._value_dps.range(self._device)
         r = self._value_dps.range(self._device)
         return DEFAULT_MIN_VALUE if r is None else r[0]
         return DEFAULT_MIN_VALUE if r is None else r[0]
 
 
     @property
     @property
     def native_max_value(self):
     def native_max_value(self):
         if self._max_dps is not None:
         if self._max_dps is not None:
-            return self._max_dps.get_value(self._device)
+            maximum = self._max_dps.get_value(self._device)
+            if maximum is not None:
+                return maximum
         r = self._value_dps.range(self._device)
         r = self._value_dps.range(self._device)
         return DEFAULT_MAX_VALUE if r is None else r[1]
         return DEFAULT_MAX_VALUE if r is None else r[1]