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

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 месеци
родитељ
комит
d0657d04d4
1 измењених фајлова са 5 додато и 1 уклоњено
  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):
         """Return the current measured temperature."""
         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
     def target_humidity(self):