Sfoglia il codice sorgente

feat (sensor): suggest actual sensor precision if not defined

In HA 2025.6 release, a change went in that redefined the default precision
to be based on sensor class rather than using all precision that the sensor
provides. This was noticed on a battery voltage sensor where the default
precision for voltage class is 0, which may be appropriate for mains voltages,
but not for a 3.6V battery voltage.
Rather than review all 1300+ configs for sensors that need to have more
precision than the new HA defaults provide, provide a default precision based
on native_precision rather than None.

PR #4119
Jason Rumney 2 mesi fa
parent
commit
975f28bc05
1 ha cambiato i file con 8 aggiunte e 1 eliminazioni
  1. 8 1
      custom_components/tuya_local/sensor.py

+ 8 - 1
custom_components/tuya_local/sensor.py

@@ -93,7 +93,14 @@ class TuyaLocalSensor(TuyaLocalEntity, SensorEntity):
     @property
     def suggested_display_precision(self):
         """Return the suggested display precision for the sensor"""
-        return self._sensor_dps.suggested_display_precision
+        precision = self._sensor_dps.suggested_display_precision
+        # if not explicitly defined, get based on scale
+        # this is in line with older HA default behavior, and avoids
+        # having to override the precision for every scaled sensor.
+        if precision is None:
+            precision = self._sensor_dps.precision(self._device)
+
+        return precision
 
     @property
     def options(self):