Prechádzať zdrojové kódy

Saswell T29UTK: changes based on new information.

From issue #45

- uncouple power and hvac_mode
- dps 112 is the configuration setting of the thermostat:
    1. 1 or 2-stage cooling
    2. 1 or 2-stage heating
    3. 1 or 2-stage heating and cooling
    5. 1/2 speed/compressor heat pump with 1 or 2 aux outputs

In config 1, the HEAT mode is not available, in config 2 COOL is not available.
Probably another dps is the aux switch for the last option.
Jason Rumney 4 rokov pred
rodič
commit
cad9926bdc

+ 21 - 25
custom_components/tuya_local/devices/saswell_t29utk_thermostat.yaml

@@ -5,12 +5,6 @@ primary_entity:
     - id: 1
       name: power
       type: boolean
-      hidden: true
-      mapping:
-        - dps_val: false
-          value: "off"
-          icon: "mdi:thermometer-off"
-          icon_priority: 1
     - id: 2
       name: temperature
       type: integer
@@ -37,28 +31,21 @@ primary_entity:
       type: string
       mapping:
         - dps_val: cold
-          constraint: power
+          value: cool
+          icon: "mdi:thermometer-minus"
+          constraint: configuration
           conditions:
-            - dps_val: true
-              value: cool
-              icon: "mdi:thermometer-minus"
-              icon_priority: 2
-            - dps_val: false
-              value_redirect: power
+            - dps_val: "2"
+              invalid: true
         - dps_val: hot
-          constraint: power
+          value: heat
+          icon: "mdi:thermometer-plus"
+          constraint: configuration
           conditions:
-            - dps_val: true
-              value: heat
-              icon: "mdi:thermometer-plus"
-              icon_priority: 2
-            - dps_val: false
-              value_redirect: power
+            - dps_val: "1"
+              invalid: true
         - dps_val: "off"
-          constraint: power
-          conditions:
-            - dps_val: false
-              value: "off"
+          value: "off"
           icon: "mdi:thermometer-off"
     - id: 5
       name: fan_mode
@@ -112,8 +99,17 @@ primary_entity:
             - dps_val: true
               value: heating
     - id: 112
-      name: unknown_112
+      name: configuration
       type: string
+      mapping:
+        - dps_val: "1"
+          value: "cooling"
+        - dps_val: "2"
+          value: "heating"
+        - dps_val: "3"
+          value: "heat/cool"
+        - dps_val: "5"
+          value: "heatpump"
     - id: 113
       name: unknown_113
       type: integer

+ 1 - 1
tests/const.py

@@ -391,7 +391,7 @@ SASWELL_T29UTK_THERMOSTAT_PAYLOAD = {
     "101": False,
     "102": False,
     "103": "cold",
-    "112": "1",
+    "112": "3",
     "113": 0,
     "114": 24,
     "115": 24,

+ 25 - 11
tests/devices/test_saswell_t29utk_thermostat.py

@@ -29,7 +29,7 @@ UNITS_DPS = "19"
 AWAY_DPS = "101"
 PROGRAM_DPS = "102"
 HVACACTION_DPS = "103"
-UNKNOWN112_DPS = "112"
+CONFIG_DPS = "112"
 UNKNOWN113_DPS = "113"
 TEMPC_DPS = "114"
 CURTEMPC_DPS = "115"
@@ -53,14 +53,13 @@ class TestSaswellT29UTKThermostat(TuyaDeviceTestCase):
         )
 
     def test_icon(self):
-        self.dps[POWER_DPS] = True
         self.dps[HVACMODE_DPS] = "cold"
         self.assertEqual(self.subject.icon, "mdi:thermometer-minus")
 
         self.dps[HVACMODE_DPS] = "hot"
         self.assertEqual(self.subject.icon, "mdi:thermometer-plus")
 
-        self.dps[POWER_DPS] = False
+        self.dps[HVACMODE_DPS] = "off"
         self.assertEqual(self.subject.icon, "mdi:thermometer-off")
 
     def test_temperature_unit(self):
@@ -122,11 +121,10 @@ class TestSaswellT29UTKThermostat(TuyaDeviceTestCase):
         self.assertEqual(self.subject.current_temperature, 25.0)
 
     def test_hvac_mode(self):
-        self.dps[POWER_DPS] = False
-        self.dps[HVACMODE_DPS] = "cold"
+        self.dps[HVACMODE_DPS] = "off"
         self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
 
-        self.dps[POWER_DPS] = True
+        self.dps[HVACMODE_DPS] = "cold"
         self.assertEqual(self.subject.hvac_mode, HVAC_MODE_COOL)
 
         self.dps[HVACMODE_DPS] = "hot"
@@ -140,22 +138,36 @@ class TestSaswellT29UTKThermostat(TuyaDeviceTestCase):
 
     async def test_turn_off(self):
         async with assert_device_properties_set(
-            self.subject._device, {POWER_DPS: False, HVACMODE_DPS: "off"}
+            self.subject._device, {HVACMODE_DPS: "off"}
         ):
             await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
 
     async def test_set_hvac_mode_cool(self):
         async with assert_device_properties_set(
-            self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "cold"}
+            self.subject._device, {HVACMODE_DPS: "cold"}
         ):
             await self.subject.async_set_hvac_mode(HVAC_MODE_COOL)
 
     async def test_set_hvac_mode_heat(self):
         async with assert_device_properties_set(
-            self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "hot"}
+            self.subject._device, {HVACMODE_DPS: "hot"}
         ):
             await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
 
+    async def test_set_hvac_mode_heat_fails_in_cooling_config(self):
+        self.dps[CONFIG_DPS] = "1"
+        with self.assertRaisesRegex(
+            AttributeError, "hvac_mode cannot be set at this time"
+        ):
+            await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
+
+    async def test_set_hvac_mode_cool_fails_in_heating_config(self):
+        self.dps[CONFIG_DPS] = "2"
+        with self.assertRaisesRegex(
+            AttributeError, "hvac_mode cannot be set at this time"
+        ):
+            await self.subject.async_set_hvac_mode(HVAC_MODE_COOL)
+
     def test_hvac_action(self):
         self.dps[POWER_DPS] = True
         self.dps[HVACACTION_DPS] = "cold"
@@ -229,7 +241,8 @@ class TestSaswellT29UTKThermostat(TuyaDeviceTestCase):
             await self.subject.async_set_preset_mode("Program")
 
     def test_device_state_attributes(self):
-        self.dps[UNKNOWN112_DPS] = "unknown112"
+        self.dps[POWER_DPS] = True
+        self.dps[CONFIG_DPS] = "2"
         self.dps[UNKNOWN113_DPS] = 113
         self.dps[TEMPC_DPS] = 114
         self.dps[CURTEMPC_DPS] = 115
@@ -239,7 +252,8 @@ class TestSaswellT29UTKThermostat(TuyaDeviceTestCase):
         self.assertDictEqual(
             self.subject.device_state_attributes,
             {
-                "unknown_112": "unknown112",
+                "power": True,
+                "configuration": "heating",
                 "unknown_113": 113,
                 "temperature_c": 114,
                 "current_temperature_c": 115,