Browse Source

water_heater: add precision attribute support, based on climate.

Issue #370
Jason Rumney 3 years ago
parent
commit
9aa7225937

+ 10 - 0
custom_components/tuya_local/water_heater.py

@@ -85,6 +85,16 @@ class TuyaLocalWaterHeater(TuyaLocalEntity, WaterHeaterEntity):
         # Return the default unit from the device
         return UnitOfTemperature.CELSIUS
 
+    @property
+    def precision(self):
+        """Return the precision of the temperature setting."""
+        # unlike sensor, this is a decimal of the smallest unit that can be
+        # represented, not a number of decimal places.
+        return 1.0 / max(
+            self._temperature_dps.scale(self._device),
+            self._current_temperature_dps.scale(self._device),
+        )
+
     @property
     def current_operation(self):
         """Return current operation ie. eco, electric, performance, ..."""

+ 4 - 1
tests/devices/test_hydrotherm_dynamicx8.py

@@ -8,7 +8,7 @@ from homeassistant.components.water_heater import (
     STATE_PERFORMANCE,
     WaterHeaterEntityFeature,
 )
-from homeassistant.const import UnitOfTemperature
+from homeassistant.const import PRECISION_WHOLE, UnitOfTemperature
 
 from ..const import HYDROTHERM_DYNAMICX8_PAYLOAD
 from ..helpers import assert_device_properties_set
@@ -50,6 +50,9 @@ class TestHydrothermDynamicX8(
     def test_temperature_unit_returns_celsius(self):
         self.assertEqual(self.subject.temperature_unit, UnitOfTemperature.CELSIUS)
 
+    def test_precision(self):
+        self.assertEqual(self.subject.precision, PRECISION_WHOLE)
+
     def test_current_temperature(self):
         self.dps[CURRENTTEMP_DP] = 55
         self.assertEqual(self.subject.current_temperature, 55)