Преглед изворни кода

Inkbird ITC-306A: Add Unbalanced error binary sensor.

In case where the probes differ by more than 3C or 5F, the ITC-306A generates
an error code 32 (E4 on display), and asserts dp 113.
- Continuous heat error is actually asserted on dp 120, not 113. (E5 on display, error code 64).  The term "unbalanced" is used, as it does not involve introducing any new terminology in the translation file.

There are also E1 and E2 errors mentioned in the manual for probe fault. And there is no mention of the missing E3, but that would account for the third unknown boolean.  But since there appears to be no order to the existing dp assignment, we cannot guess as to which dp maps to which, and despite the explanation in the manual including "probe unplugged", they appear to be hard wired, so cannot be tested easily.
Jason Rumney пре 4 година
родитељ
комит
2e7e94e7e3

+ 24 - 25
custom_components/tuya_local/devices/inkbird_itc306a_thermostat.yaml

@@ -12,11 +12,6 @@ primary_entity:
     - id: 101
     - id: 101
       type: string
       type: string
       name: temperature_unit
       name: temperature_unit
-    - id: 102
-      type: integer
-      name: temperature_calibration_offset
-      mapping:
-        - scale: 10
     - id: 103
     - id: 103
       type: string
       type: string
       name: preset_mode
       name: preset_mode
@@ -32,7 +27,7 @@ primary_entity:
       name: current_temperature
       name: current_temperature
       mapping:
       mapping:
         - scale: 10
         - scale: 10
-        - constraint: temperature_unit
+          constraint: temperature_unit
           conditions:
           conditions:
             - dps_val: F
             - dps_val: F
               value_redirect: current_temperature_f
               value_redirect: current_temperature_f
@@ -50,22 +45,10 @@ primary_entity:
               range:
               range:
                 min: 320
                 min: 320
                 max: 1130
                 max: 1130
-    - id: 108
-      type: integer
-      name: heat_time_alarm_threshold_hours
-    - id: 109
-      type: integer
-      name: high_temp_alarm_threshold
-      mapping:
-        - scale: 10
-    - id: 110
-      type: integer
-      name: low_temp_alarm_threshold
-      mapping:
-        - scale: 10
     - id: 111
     - id: 111
       type: boolean
       type: boolean
       name: high_temp_alarm
       name: high_temp_alarm
+      hidden: true
       mapping:
       mapping:
         - dps_val: true
         - dps_val: true
           icon: "mdi:thermometer-alert"
           icon: "mdi:thermometer-alert"
@@ -73,13 +56,15 @@ primary_entity:
     - id: 112
     - id: 112
       type: boolean
       type: boolean
       name: low_temp_alarm
       name: low_temp_alarm
+      hidden: true
       mapping:
       mapping:
         - dps_val: true
         - dps_val: true
-          icon: "mdi:thermometer-alert"
+          icon: "mdi:snowflake-alert"
           icon_priority: 2
           icon_priority: 2
     - id: 113
     - id: 113
       type: boolean
       type: boolean
-      name: heat_time_alarm
+      name: temperature_difference_alarm
+      hidden: true
       mapping:
       mapping:
         - dps_val: true
         - dps_val: true
           icon: "mdi:thermometer-alert"
           icon: "mdi:thermometer-alert"
@@ -104,11 +89,11 @@ primary_entity:
       mapping:
       mapping:
         - dps_val: true
         - dps_val: true
           icon: "mdi:thermometer"
           icon: "mdi:thermometer"
-          icon_priority: 5
+          icon_priority: 6
           value: heating
           value: heating
         - dps_val: false
         - dps_val: false
           icon: "mdi:thermometer-off"
           icon: "mdi:thermometer-off"
-          icon_priority: 4
+          icon_priority: 5
           value: idle
           value: idle
     - id: 116
     - id: 116
       type: integer
       type: integer
@@ -127,7 +112,12 @@ primary_entity:
       name: unknown_119
       name: unknown_119
     - id: 120
     - id: 120
       type: boolean
       type: boolean
-      name: unknown_120
+      name: heat_time_alarm
+      hidden: true
+      mapping:
+        - dps_val: true
+          icon: "mdi:clock-alert"
+          icon_priority: 4
 secondary_entities:
 secondary_entities:
   - entity: number
   - entity: number
     category: config
     category: config
@@ -244,7 +234,7 @@ secondary_entities:
     category: diagnostic
     category: diagnostic
     name: Continuous Heat
     name: Continuous Heat
     dps:
     dps:
-      - id: 113
+      - id: 120
         type: boolean
         type: boolean
         name: sensor
         name: sensor
   - entity: binary_sensor
   - entity: binary_sensor
@@ -259,3 +249,12 @@ secondary_entities:
           - dps_val: 0
           - dps_val: 0
             value: false
             value: false
           - value: true
           - value: true
+  - entity: binary_sensor
+    class: problem
+    category: diagnostic
+    name: Unbalanced
+    icon: "mdi:scale-unbalanced"
+    dps:
+      - id: 113
+        type: boolean
+        name: sensor

+ 17 - 21
tests/devices/test_inkbird_itc306a_thermostat.py

@@ -30,14 +30,14 @@ HIGH_THRES_DPS = "109"
 LOW_THRES_DPS = "110"
 LOW_THRES_DPS = "110"
 ALARM_HIGH_DPS = "111"
 ALARM_HIGH_DPS = "111"
 ALARM_LOW_DPS = "112"
 ALARM_LOW_DPS = "112"
-ALARM_TIME_DPS = "113"
+ALARM_DIFF_DPS = "113"
 TEMPHIGH_DPS = "114"
 TEMPHIGH_DPS = "114"
 SWITCH_DPS = "115"
 SWITCH_DPS = "115"
 TEMPF_DPS = "116"
 TEMPF_DPS = "116"
 UNKNOWN117_DPS = "117"
 UNKNOWN117_DPS = "117"
 UNKNOWN118_DPS = "118"
 UNKNOWN118_DPS = "118"
 UNKNOWN119_DPS = "119"
 UNKNOWN119_DPS = "119"
-UNKNOWN120_DPS = "120"
+ALARM_TIME_DPS = "120"
 
 
 
 
 class TestInkbirdThermostat(
 class TestInkbirdThermostat(
@@ -78,6 +78,11 @@ class TestInkbirdThermostat(
                     "dps": ALARM_TIME_DPS,
                     "dps": ALARM_TIME_DPS,
                     "device_class": DEVICE_CLASS_PROBLEM,
                     "device_class": DEVICE_CLASS_PROBLEM,
                 },
                 },
+                {
+                    "name": "binary_sensor_unbalanced",
+                    "dps": ALARM_DIFF_DPS,
+                    "device_class": DEVICE_CLASS_PROBLEM,
+                },
                 {
                 {
                     "name": "binary_sensor_error",
                     "name": "binary_sensor_error",
                     "dps": ERROR_DPS,
                     "dps": ERROR_DPS,
@@ -129,6 +134,7 @@ class TestInkbirdThermostat(
                 "binary_sensor_high_temperature",
                 "binary_sensor_high_temperature",
                 "binary_sensor_low_temperature",
                 "binary_sensor_low_temperature",
                 "binary_sensor_continuous_heat",
                 "binary_sensor_continuous_heat",
+                "binary_sensor_unbalanced",
                 "binary_sensor_error",
                 "binary_sensor_error",
                 "number_calibration_offset",
                 "number_calibration_offset",
                 "number_continuous_heat_hours",
                 "number_continuous_heat_hours",
@@ -162,10 +168,14 @@ class TestInkbirdThermostat(
 
 
         self.dps[ALARM_HIGH_DPS] = False
         self.dps[ALARM_HIGH_DPS] = False
         self.dps[ALARM_LOW_DPS] = True
         self.dps[ALARM_LOW_DPS] = True
-        self.assertEqual(self.subject.icon, "mdi:thermometer-alert")
+        self.assertEqual(self.subject.icon, "mdi:snowflake-alert")
 
 
         self.dps[ALARM_LOW_DPS] = False
         self.dps[ALARM_LOW_DPS] = False
         self.dps[ALARM_TIME_DPS] = True
         self.dps[ALARM_TIME_DPS] = True
+        self.assertEqual(self.subject.icon, "mdi:clock-alert")
+
+        self.dps[ALARM_TIME_DPS] = False
+        self.dps[ALARM_DIFF_DPS] = True
         self.assertEqual(self.subject.icon, "mdi:thermometer-alert")
         self.assertEqual(self.subject.icon, "mdi:thermometer-alert")
 
 
     def test_climate_hvac_modes(self):
     def test_climate_hvac_modes(self):
@@ -221,8 +231,12 @@ class TestInkbirdThermostat(
             self.subject._device.anticipate_property_value.assert_not_called()
             self.subject._device.anticipate_property_value.assert_not_called()
 
 
     def test_current_temperature(self):
     def test_current_temperature(self):
+        self.dps[UNIT_DPS] = "C"
         self.dps[CURRENTTEMP_DPS] = 289
         self.dps[CURRENTTEMP_DPS] = 289
         self.assertEqual(self.subject.current_temperature, 28.9)
         self.assertEqual(self.subject.current_temperature, 28.9)
+        self.dps[UNIT_DPS] = "F"
+        self.dps[TEMPF_DPS] = 789
+        self.assertEqual(self.subject.current_temperature, 78.9)
 
 
     def test_temperature_unit(self):
     def test_temperature_unit(self):
         self.dps[UNIT_DPS] = "F"
         self.dps[UNIT_DPS] = "F"
@@ -286,34 +300,16 @@ class TestInkbirdThermostat(
 
 
     def test_extra_state_attributes(self):
     def test_extra_state_attributes(self):
         self.dps[ERROR_DPS] = 1
         self.dps[ERROR_DPS] = 1
-        self.dps[CALIBRATE_DPS] = 1
-        self.dps[TIME_THRES_DPS] = 5
-        self.dps[HIGH_THRES_DPS] = 400
-        self.dps[LOW_THRES_DPS] = 300
-        self.dps[ALARM_HIGH_DPS] = True
-        self.dps[ALARM_LOW_DPS] = False
-        self.dps[ALARM_TIME_DPS] = True
-        self.dps[TEMPF_DPS] = 999
         self.dps[UNKNOWN117_DPS] = True
         self.dps[UNKNOWN117_DPS] = True
         self.dps[UNKNOWN118_DPS] = False
         self.dps[UNKNOWN118_DPS] = False
         self.dps[UNKNOWN119_DPS] = True
         self.dps[UNKNOWN119_DPS] = True
-        self.dps[UNKNOWN120_DPS] = False
 
 
         self.assertDictEqual(
         self.assertDictEqual(
             self.subject.extra_state_attributes,
             self.subject.extra_state_attributes,
             {
             {
                 "error": 1,
                 "error": 1,
-                "temperature_calibration_offset": 0.1,
-                "heat_time_alarm_threshold_hours": 5,
-                "high_temp_alarm_threshold": 40.0,
-                "low_temp_alarm_threshold": 30.0,
-                "high_temp_alarm": True,
-                "low_temp_alarm": False,
-                "heat_time_alarm": True,
-                "current_temperature_f": 99.9,
                 "unknown_117": True,
                 "unknown_117": True,
                 "unknown_118": False,
                 "unknown_118": False,
                 "unknown_119": True,
                 "unknown_119": True,
-                "unknown_120": False,
             },
             },
         )
         )