Просмотр исходного кода

Siswell thermostat: use separate c and f temperature dps to set temperature.

This device appears to have 3 dps corresponding to the set temperature, dps 2 which is in tenths of degrees, dps 114 which is always C, in degrees, and dps 116 which is always F, in degrees.

Previously we tried to use dps 2, as it has more precision, but this does not seem to work (comment on Issue #45).  Try the others instead.
Jason Rumney 4 лет назад
Родитель
Сommit
636d0cd4cb

+ 17 - 14
custom_components/tuya_local/devices/saswell_t29utk_thermostat.yaml

@@ -10,22 +10,10 @@ primary_entity:
         - dps_val: false
           value: "off"
     - id: 2
-      name: temperature
+      name: set_temperature
       type: integer
       mapping:
         - scale: 10
-          constraint: temperature_unit
-          conditions:
-            - dps_val: c
-              range:
-                min: 50
-                max: 350
-              step: 5
-            - dps_val: f
-              range:
-                min: 410
-                max: 950
-              step: 10
     - id: 3
       name: current_temperature
       type: integer
@@ -109,14 +97,29 @@ primary_entity:
       name: unknown_113
       type: integer
     - id: 114
-      name: temperature_c
+      name: temperature
       type: integer
+      mapping:
+        - constraint: temperature_unit
+          conditions:
+            - dps_val: c
+              range:
+                min: 5
+                max: 35
+            - dps_val: f
+              value_redirect: temperature_f
+              range:
+                min: 41
+                max: 95
     - id: 115
       name: current_temperature_c
       type: integer
     - id: 116
       name: temperature_f
       type: integer
+      range:
+        min: 41
+        max: 95
     - id: 117
       name: current_temperature_f
       type: integer

+ 18 - 15
tests/devices/test_saswell_t29utk_thermostat.py

@@ -22,7 +22,7 @@ from ..helpers import assert_device_properties_set
 from .base_device_tests import TuyaDeviceTestCase
 
 POWER_DPS = "1"
-TEMPERATURE_DPS = "2"
+SETTEMP_DPS = "2"
 CURRENTTEMP_DPS = "3"
 HVACACTION_DPS = "4"
 FAN_DPS = "5"
@@ -32,7 +32,7 @@ PROGRAM_DPS = "102"
 HVACMODE_DPS = "103"
 UNKNOWN112_DPS = "112"
 UNKNOWN113_DPS = "113"
-TEMPC_DPS = "114"
+TEMPERATURE_DPS = "114"
 CURTEMPC_DPS = "115"
 TEMPF_DPS = "116"
 CURTEMPF_DPS = "117"
@@ -75,13 +75,14 @@ class TestSaswellT29UTKThermostat(TuyaDeviceTestCase):
         self.assertEqual(self.subject.temperature_unit, TEMP_FAHRENHEIT)
 
     def test_target_temperature(self):
-        self.dps[TEMPERATURE_DPS] = 250
-        self.assertEqual(self.subject.target_temperature, 25.0)
-
-    def test_target_temperature_step(self):
         self.dps[UNITS_DPS] = "c"
-        self.assertEqual(self.subject.target_temperature_step, 0.5)
+        self.dps[TEMPERATURE_DPS] = 25
+        self.dps[TEMPF_DPS] = 75
+        self.assertEqual(self.subject.target_temperature, 25)
         self.dps[UNITS_DPS] = "f"
+        self.assertEqual(self.subject.target_temperature, 75)
+
+    def test_target_temperature_step(self):
         self.assertEqual(self.subject.target_temperature_step, 1)
 
     def test_minimum_target_temperature(self):
@@ -91,22 +92,24 @@ class TestSaswellT29UTKThermostat(TuyaDeviceTestCase):
         self.assertEqual(self.subject.max_temp, 35)
 
     async def test_set_target_temperature(self):
+        self.dps[UNITS_DPS] = "c"
         async with assert_device_properties_set(
             self.subject._device,
-            {TEMPERATURE_DPS: 245},
+            {TEMPERATURE_DPS: 24},
         ):
-            await self.subject.async_set_target_temperature(24.5)
+            await self.subject.async_set_target_temperature(24)
 
-    async def test_set_target_temperature_rounds_value_to_half_degrees(self):
+    async def test_set_target_temperature_f(self):
+        self.dps[UNITS_DPS] = "f"
         async with assert_device_properties_set(
             self.subject._device,
-            {TEMPERATURE_DPS: 245},
+            {TEMPF_DPS: 74},
         ):
-            await self.subject.async_set_target_temperature(24.6)
+            await self.subject.async_set_target_temperature(74)
 
     async def test_set_target_temperature_fails_outside_valid_range(self):
         with self.assertRaisesRegex(
-            ValueError, "temperature \\(4\\) must be between 5.0 and 35.0"
+            ValueError, "temperature \\(4\\) must be between 5 and 35"
         ):
             await self.subject.async_set_target_temperature(4)
 
@@ -224,9 +227,9 @@ class TestSaswellT29UTKThermostat(TuyaDeviceTestCase):
             await self.subject.async_set_preset_mode("Program")
 
     def test_device_state_attributes(self):
+        self.dps[SETTEMP_DPS] = 2
         self.dps[UNKNOWN112_DPS] = "unknown112"
         self.dps[UNKNOWN113_DPS] = 113
-        self.dps[TEMPC_DPS] = 114
         self.dps[CURTEMPC_DPS] = 115
         self.dps[TEMPF_DPS] = 116
         self.dps[CURTEMPF_DPS] = 117
@@ -234,9 +237,9 @@ class TestSaswellT29UTKThermostat(TuyaDeviceTestCase):
         self.assertCountEqual(
             self.subject.device_state_attributes,
             {
+                "set_temperature": 0.2,
                 "unknown_112": "unknown112",
                 "unknown_113": 113,
-                "temperature_c": 114,
                 "current_temperature_c": 115,
                 "temperature_f": 116,
                 "current_temperature_f": 117,