Przeglądaj źródła

feat (climate): allow precision to be specified for current temp

When there is a unit mismatch, it is useful to be able to scale
into the expected range using target_range. But this results in fractional
temperatures, which are unexpected. Allow precision to be specified in
the current_temperature dp, and use it to round the value after scaling.

This is different to the use of precision in sensors to inform the UI of a
suggested precision without actually rounding, but it makes sense in this
context.

For PR #4051
Jason Rumney 2 miesięcy temu
rodzic
commit
d0657d04d4
1 zmienionych plików z 5 dodań i 1 usunięć
  1. 5 1
      custom_components/tuya_local/climate.py

+ 5 - 1
custom_components/tuya_local/climate.py

@@ -282,7 +282,11 @@ class TuyaLocalClimate(TuyaLocalEntity, ClimateEntity):
     def current_temperature(self):
     def current_temperature(self):
         """Return the current measured temperature."""
         """Return the current measured temperature."""
         if self._current_temperature_dps:
         if self._current_temperature_dps:
-            return self._current_temperature_dps.get_value(self._device)
+            temp = self._current_temperature_dps.get_value(self._device)
+            if self._current_temperature_dps.suggested_precision is not None:
+                # Round the value to the suggested precision
+                temp = round(temp, self._current_temperature_dps.suggested_precision)
+            return temp
 
 
     @property
     @property
     def target_humidity(self):
     def target_humidity(self):