Jelajahi Sumber

W'eau pool heatpump: add eco mode and fault binary sensor.

Issue #152
Jason Rumney 3 tahun lalu
induk
melakukan
4fcf337f72

+ 33 - 24
custom_components/tuya_local/devices/weau_pool_heatpump.yaml

@@ -4,11 +4,21 @@ primary_entity:
   dps:
     - id: 1
       type: boolean
-      name: power
-      hidden: true
+      name: hvac_mode
       mapping:
         - dps_val: false
           value: "off"
+        - dps_val: true
+          constraint: preset_mode
+          conditions:
+            - dps_val: eco
+              value: heat
+            - dps_val: hot
+              value: heat
+            - dps_val: cold
+              value: cool
+            - dps_val: auto
+              value: heat_cool
     - id: 2
       type: integer
       name: temperature
@@ -22,30 +32,29 @@ primary_entity:
         - scale: 10
     - id: 4
       type: string
-      name: hvac_mode
+      name: preset_mode
       mapping:
         - dps_val: hot
-          constraint: power
-          conditions:
-            - dps_val: false
-              value_redirect: power
-              value: "off"
-            - dps_val: true
-              value: heat
+          value: Boost Heat
+        - dps_val: eco
+          value: Eco Heat
         - dps_val: cold
-          constraint: power
-          conditions:
-            - dps_val: false
-              value_redirect: power
-            - dps_val: true
-              value: cool
+          value: Cool
         - dps_val: auto
-          constraint: power
-          conditions:
-            - dps_val: false
-              value_redirect: power
-            - dps_val: true
-              value: heat_cool
+          value: Auto
     - id: 6
-      type: integer
-      name: unknown_6
+      name: fault
+      type: bitfield
+secondary_entities:
+  - entity: binary_sensor
+    class: problem
+    name: Fault
+    category: diagnostic
+    dps:
+      - id: 6
+        type: bitfield
+        name: sensor
+        mapping:
+          - dps_val: 0
+            value: false
+          - value: true

+ 55 - 12
tests/devices/test_weau_pool_heatpump.py

@@ -1,22 +1,24 @@
+from homeassistant.components.binary_sensor import BinarySensorDeviceClass
 from homeassistant.components.climate.const import (
     ClimateEntityFeature,
     HVACMode,
 )
-from homeassistant.const import TEMP_CELSIUS
 
 from ..const import WEAU_POOL_HEATPUMP_PAYLOAD
 from ..helpers import assert_device_properties_set
+from ..mixins.binary_sensor import BasicBinarySensorTests
 from ..mixins.climate import TargetTemperatureTests
 from .base_device_tests import TuyaDeviceTestCase
 
 POWER_DPS = "1"
 TEMPERATURE_DPS = "2"
 CURRENTTEMP_DPS = "3"
-HVACMODE_DPS = "4"
-UNKNOWN6_DPS = "6"
+MODE_DPS = "4"
+FAULT_DPS = "6"
 
 
 class TestWeauPoolHeatpump(
+    BasicBinarySensorTests,
     TargetTemperatureTests,
     TuyaDeviceTestCase,
 ):
@@ -31,11 +33,18 @@ class TestWeauPoolHeatpump(
             min=7,
             max=60,
         )
+        self.setUpBasicBinarySensor(
+            FAULT_DPS,
+            self.entities.get("binary_sensor_fault"),
+            device_class=BinarySensorDeviceClass.PROBLEM,
+            testdata=(4, 0),
+        )
+        self.mark_secondary(["binary_sensor_fault"])
 
     def test_supported_features(self):
         self.assertEqual(
             self.subject.supported_features,
-            ClimateEntityFeature.TARGET_TEMPERATURE,
+            ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE,
         )
 
     def test_current_temperature(self):
@@ -44,12 +53,16 @@ class TestWeauPoolHeatpump(
 
     def test_hvac_mode(self):
         self.dps[POWER_DPS] = True
-        self.dps[HVACMODE_DPS] = "hot"
+        self.dps[MODE_DPS] = "hot"
         self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
-        self.dps[HVACMODE_DPS] = "cold"
+        self.dps[MODE_DPS] = "cold"
         self.assertEqual(self.subject.hvac_mode, HVACMode.COOL)
-        self.dps[HVACMODE_DPS] = "auto"
+        self.dps[MODE_DPS] = "auto"
         self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT_COOL)
+        self.dps[MODE_DPS] = "eco"
+        self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
+        self.dps[POWER_DPS] = False
+        self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
 
     def test_hvac_modes(self):
         self.assertCountEqual(
@@ -67,24 +80,54 @@ class TestWeauPoolHeatpump(
     async def test_set_cool(self):
         async with assert_device_properties_set(
             self.subject._device,
-            {POWER_DPS: True, HVACMODE_DPS: "cold"},
+            {POWER_DPS: True, MODE_DPS: "cold"},
         ):
             await self.subject.async_set_hvac_mode(HVACMode.COOL)
 
     async def test_set_heat(self):
         async with assert_device_properties_set(
             self.subject._device,
-            {POWER_DPS: True, HVACMODE_DPS: "hot"},
+            {POWER_DPS: True, MODE_DPS: "eco"},
         ):
             await self.subject.async_set_hvac_mode(HVACMode.HEAT)
 
     async def test_set_auto(self):
         async with assert_device_properties_set(
             self.subject._device,
-            {POWER_DPS: True, HVACMODE_DPS: "auto"},
+            {POWER_DPS: True, MODE_DPS: "auto"},
         ):
             await self.subject.async_set_hvac_mode(HVACMode.HEAT_COOL)
 
+    def test_preset_mode(self):
+        self.dps[MODE_DPS] = "eco"
+        self.assertEqual(self.subject.preset_mode, "Eco Heat")
+        self.dps[MODE_DPS] = "hot"
+        self.assertEqual(self.subject.preset_mode, "Boost Heat")
+        self.dps[MODE_DPS] = "cold"
+        self.assertEqual(self.subject.preset_mode, "Cool")
+        self.dps[MODE_DPS] = "auto"
+        self.assertEqual(self.subject.preset_mode, "Auto")
+
+    def test_preset_modes(self):
+        self.assertCountEqual(
+            self.subject.preset_modes,
+            ["Eco Heat", "Boost Heat", "Cool", "Auto"],
+        )
+
+    async def test_set_preset_to_boost(self):
+        async with assert_device_properties_set(
+            self.subject._device,
+            {MODE_DPS: "hot"},
+        ):
+            await self.subject.async_set_preset_mode("Boost Heat")
+
+    async def test_set_preset_to_eco(self):
+        async with assert_device_properties_set(
+            self.subject._device,
+            {MODE_DPS: "eco"},
+        ):
+            await self.subject.async_set_preset_mode("Eco Heat")
+
     def test_extra_state_attributes(self):
-        self.dps[UNKNOWN6_DPS] = 6
-        self.assertDictEqual(self.subject.extra_state_attributes, {"unknown_6": 6})
+        self.dps[FAULT_DPS] = 6
+        self.assertDictEqual(self.subject.extra_state_attributes, {"fault": 6})