Prechádzať zdrojové kódy

Hysen thermostat: add unit selection, display selection and fault.

Previously unknown dps identified.

Issue #254
Jason Rumney 3 rokov pred
rodič
commit
7d84030287

+ 1 - 0
ACKNOWLEDGEMENTS.md

@@ -122,3 +122,4 @@ Further device support has been made with the assistance of users.  Please consi
 - [dilorenzo1987](https://github.com/dilorenzo1987) for contributing support for Stadler Form Roger purifiers.
 - [fsevilla3](https://github.com/fsevilla3) for contributing support for water_heater entities and Hydrotherm Dynamix/X8 water heaters.
 - [allistermaguire](https://github.com/allistermaguire) for contributing improvements to Saswell C16 thermostats.
+- [karnas99](https://github.com/karnas99) for assistance in improving Hysen thermostat support.

+ 154 - 22
custom_components/tuya_local/devices/hysen_hy08we2_thermostat.yaml

@@ -18,7 +18,12 @@ primary_entity:
         max: 1220
       mapping:
         - scale: 10
-          step: 5
+          constraint: temperature_unit
+          conditions:
+            - dps_val: false
+              step: 5
+            - dps_val: true
+              step: 10
     - id: 3
       type: integer
       name: current_temperature
@@ -37,11 +42,16 @@ primary_entity:
         - dps_val: Holiday
           value: Holiday
     - id: 12
-      type: integer
-      name: unknown_12
+      type: bitfield
+      name: fault_code
     - id: 101
       type: boolean
-      name: unknown_101
+      name: temperature_unit
+      mapping:
+        - dps_val: false
+          value: C
+        - dps_val: true
+          value: F
     - id: 102
       type: boolean
       name: hvac_action
@@ -61,9 +71,6 @@ primary_entity:
     - id: 107
       type: boolean
       name: unknown_107
-    - id: 108
-      type: boolean
-      name: unknown_108
     - id: 114
       type: integer
       name: max_temperature
@@ -91,9 +98,16 @@ secondary_entities:
         type: integer
         name: sensor
         class: measurement
-        unit: C
         mapping:
           - scale: 10
+      - id: 101
+        type: boolean
+        name: unit
+        mapping:
+          - dps_val: false
+            value: C
+          - dps_val: true
+            value: F
   - entity: number
     name: Holiday days
     category: config
@@ -111,8 +125,15 @@ secondary_entities:
     dps:
       - id: 105
         type: integer
-        unit: C
         name: value
+      - id: 101
+        type: boolean
+        name: unit
+        mapping:
+          - dps_val: false
+            value: C
+          - dps_val: true
+            value: F
       - id: 114
         type: integer
         name: maximum
@@ -123,13 +144,20 @@ secondary_entities:
     name: Calibration offset
     category: config
     dps:
-    - id: 109
-      type: integer
-      name: value
-      unit: C
-      range:
-        min: -9
-        max: 9
+      - id: 109
+        type: integer
+        name: value
+        range:
+          min: -9
+          max: 9
+      - id: 101
+        type: boolean
+        name: unit
+        mapping:
+          - dps_val: false
+            value: C
+          - dps_val: true
+            value: F
   - entity: number
     name: Calibration swing internal
     category: config
@@ -137,12 +165,19 @@ secondary_entities:
       - id: 110
         type: integer
         name: value
-        unit: C
         range:
           min: 5
           max: 25
         mapping:
           - scale: 10
+      - id: 101
+        type: boolean
+        name: unit
+        mapping:
+          - dps_val: false
+            value: C
+          - dps_val: true
+            value: F
   - entity: number
     name: Calibration swing external
     category: config
@@ -150,12 +185,19 @@ secondary_entities:
       - id: 111
         type: integer
         name: value
-        unit: C
         range:
           min: 1
           max: 10
         mapping:
           - scale: 10
+      - id: 101
+        type: boolean
+        name: unit
+        mapping:
+          - dps_val: false
+            value: C
+          - dps_val: true
+            value: F
   - entity: number
     name: High temperature protection
     category: config
@@ -163,10 +205,23 @@ secondary_entities:
       - id: 112
         type: integer
         name: value
-        unit: C
         range:
           min: 35
           max: 70
+        constraint: unit
+        conditions:
+          - dps_val: true
+            range:
+              min: 95
+              max: 158
+      - id: 101
+        type: boolean
+        name: unit
+        mapping:
+          - dps_val: false
+            value: C
+          - dps_val: true
+            value: F
   - entity: number
     name: Low temperature protection
     category: config
@@ -174,10 +229,23 @@ secondary_entities:
       - id: 113
         type: integer
         name: value
-        unit: C
         range:
           min: 1
           max: 10
+        constraint: unit
+        conditions:
+          - dps_val: true
+            range:
+              min: 34
+              max: 50
+      - id: 101
+        type: boolean
+        name: unit
+        mapping:
+          - dps_val: false
+            value: C
+          - dps_val: true
+            value: F
   - entity: number
     name: High temperature limit
     category: config
@@ -185,10 +253,23 @@ secondary_entities:
       - id: 114
         type: integer
         name: value
-        unit: C
         range:
           min: 2
           max: 70
+        constraint: unit
+        conditions:
+          - dps_val: true
+            range:
+              min: 36
+              max: 158
+      - id: 101
+        type: boolean
+        name: unit
+        mapping:
+          - dps_val: false
+            value: C
+          - dps_val: true
+            value: F
   - entity: number
     name: Low temperature limit
     category: config
@@ -196,10 +277,23 @@ secondary_entities:
       - id: 115
         type: integer
         name: value
-        unit: C
         range:
           min: 1
           max: 10
+        constraint: unit
+        conditions:
+          - dps_val: true
+            range:
+              min: 34
+              max: 50
+      - id: 101
+        type: boolean
+        name: unit
+        mapping:
+          - dps_val: false
+            value: C
+          - dps_val: true
+            value: F
   - entity: select
     name: Temperature sensor
     category: config
@@ -242,3 +336,41 @@ secondary_entities:
             value: 6 + 1 day
           - dps_val: 2days
             value: 5 + 2 day
+  - entity: select
+    name: Temperature unit
+    category: config
+    icon: "mdi:temperature-celsius"
+    dps:
+      - id: 101
+        type: boolean
+        name: option
+        mapping:
+          - dps_val: false
+            value: Celsius
+          - dps_val: true
+            value: Fahrenheit
+  - entity: select
+    name: Display Temperature
+    category: config
+    icon: "mdi:thermometer"
+    dps:
+      - id: 108
+        type: boolean
+        name: option
+        mapping:
+          - dps_val: false
+            value: Internal
+          - dps_val: true
+            value: External
+  - entity: binary_sensor
+    name: Fault
+    class: problem
+    category: diagnostic
+    dps:
+      - id: 12
+        name: sensor
+        type: bitfield
+        mapping:
+          - dps_val: 0
+            value: false
+          - value: true

+ 39 - 12
tests/devices/test_hysen_hy08we2_thermostat.py

@@ -1,13 +1,17 @@
+from homeassistant.components.binary_sensor import (
+    BinarySensorDeviceClass,
+)
 from homeassistant.components.climate.const import (
     ClimateEntityFeature,
     HVACAction,
     HVACMode,
 )
 from homeassistant.components.sensor import SensorDeviceClass
-from homeassistant.const import TEMP_CELSIUS, TIME_DAYS
+from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT, TIME_DAYS
 
 from ..const import HYSEN_HY08WE2_THERMOSTAT_PAYLOAD
 from ..helpers import assert_device_properties_set
+from ..mixins.binary_sensor import BasicBinarySensorTests
 from ..mixins.climate import TargetTemperatureTests
 from ..mixins.lock import BasicLockTests
 from ..mixins.number import MultiNumberTests
@@ -20,15 +24,15 @@ TEMPERATURE_DPS = "2"
 CURRENTTEMP_DPS = "3"
 PRESET_DPS = "4"
 LOCK_DPS = "6"
-UNKNOWN12_DPS = "12"
-UNKNOWN101_DPS = "101"
+ERROR_DPS = "12"
+UNIT_DPS = "101"
 HVACACTION_DPS = "102"
 EXTTEMP_DPS = "103"
 HOLIDAYS_DPS = "104"
 HOLIDAYTEMP_DPS = "105"
 UNKNOWN106_DPS = "106"
 UNKNOWN107_DPS = "107"
-UNKNOWN108_DPS = "108"
+DISPLAY_DPS = "108"
 CALIBOFFSET_DPS = "109"
 CALIBSWINGINT_DPS = "110"
 CALIBSWINGEXT_DPS = "111"
@@ -42,10 +46,11 @@ SCHED_DPS = "118"
 
 
 class TestHysenHY08WE2Thermostat(
+    BasicBinarySensorTests,
     BasicLockTests,
+    BasicSensorTests,
     MultiNumberTests,
     MultiSelectTests,
-    BasicSensorTests,
     TargetTemperatureTests,
     TuyaDeviceTestCase,
 ):
@@ -66,6 +71,13 @@ class TestHysenHY08WE2Thermostat(
             step=5,
         )
         self.setUpBasicLock(LOCK_DPS, self.entities.get("lock_child_lock"))
+        self.setUpBasicBinarySensor(
+            ERROR_DPS,
+            self.entities.get("binary_sensor_fault"),
+            testdata=(1, 0),
+            device_class=BinarySensorDeviceClass.PROBLEM,
+        )
+
         self.setUpMultiSelect(
             [
                 {
@@ -95,6 +107,22 @@ class TestHysenHY08WE2Thermostat(
                         "all": "Both",
                     },
                 },
+                {
+                    "dps": UNIT_DPS,
+                    "name": "select_temperature_unit",
+                    "options": {
+                        False: "Celsius",
+                        True: "Fahrenheit",
+                    },
+                },
+                {
+                    "dps": DISPLAY_DPS,
+                    "name": "select_display_temperature",
+                    "options": {
+                        False: "Internal",
+                        True: "External",
+                    },
+                },
             ],
         )
         self.setUpBasicSensor(
@@ -178,6 +206,7 @@ class TestHysenHY08WE2Thermostat(
         )
         self.mark_secondary(
             [
+                "binary_sensor_fault",
                 "lock_child_lock",
                 "number_holiday_days",
                 "number_holiday_temperature",
@@ -188,9 +217,11 @@ class TestHysenHY08WE2Thermostat(
                 "number_low_temperature_protection",
                 "number_low_temperature_limit",
                 "number_high_temperature_limit",
-                "select_temperature_sensor",
+                "select_display_temperature",
                 "select_initial_state",
                 "select_schedule",
+                "select_temperature_sensor",
+                "select_temperature_unit",
             ],
         )
 
@@ -279,19 +310,15 @@ class TestHysenHY08WE2Thermostat(
             await self.subject.async_set_target_temperature(122.5)
 
     def test_extra_state_attributes(self):
-        self.dps[UNKNOWN12_DPS] = 12
-        self.dps[UNKNOWN101_DPS] = True
+        self.dps[ERROR_DPS] = 12
         self.dps[UNKNOWN106_DPS] = False
         self.dps[UNKNOWN107_DPS] = True
-        self.dps[UNKNOWN108_DPS] = False
         self.assertDictEqual(
             self.subject.extra_state_attributes,
             {
-                "unknown_12": 12,
-                "unknown_101": True,
+                "fault_code": 12,
                 "unknown_106": False,
                 "unknown_107": True,
-                "unknown_108": False,
             },
         )