Procházet zdrojové kódy

Implement tests for Blitzwolf BW-SH2 humidifier

- user reports that setting speed does not work.  Tests should reveal
and config issues causing thiss.

- Rename both Blitzwolf humidifiers, replacing - with _ in file name.
HA is probably more robust now, but hyphens in config file names used
to generate invalid entity names.

Issue #410
Jason Rumney před 3 roky
rodič
revize
e80cd8361e

+ 0 - 0
custom_components/tuya_local/devices/blitzwolf_bwsh2-humidifier.yaml → custom_components/tuya_local/devices/blitzwolf_bwsh2_humidifier.yaml


+ 0 - 0
custom_components/tuya_local/devices/blitzwolf_bwsh5-humidifier.yaml → custom_components/tuya_local/devices/blitzwolf_bwsh5_humidifier.yaml


+ 7 - 0
tests/const.py

@@ -1533,3 +1533,10 @@ MOTION_LIGHT_PAYLOAD = {
     "105": 374,
     "106": False,
 }
+
+BLITZWOLF_BWSH2_PAYLOAD = {
+    "1": True,
+    "3": "grade1",
+    "6": "close",
+    "19": "cancel",
+}

+ 84 - 0
tests/devices/test_blitzwolf_bsh2_humidifier.py

@@ -0,0 +1,84 @@
+from homeassistant.components.fan import FanEntityFeature
+
+from ..const import BLITZWOLF_BWSH2_PAYLOAD
+from ..helpers import assert_device_properties_set
+from ..mixins.select import MultiSelectTests
+from .base_device_tests import TuyaDeviceTestCase
+
+SWITCH_DP = "1"
+SPEED_DP = "3"
+LIGHT_DP = "6"
+TIMER_DP = "19"
+
+
+class TestBlitzwolfSH2Humidifier(MultiSelectTests, TuyaDeviceTestCase):
+    __test__ = True
+
+    def setUp(self):
+        self.setUpForConfig(
+            "blitzwolf_bwsh2_humidifier.yaml",
+            BLITZWOLF_BWSH2_PAYLOAD,
+        )
+        self.subject = self.entities.get("fan")
+        self.setUpMultiSelect(
+            [
+                {
+                    "name": "select_light",
+                    "dps": LIGHT_DP,
+                    "options": {
+                        "close": "Off",
+                        "purple": "Purple",
+                        "blue": "Blue",
+                        "cyan": "Cyan",
+                        "green": "Green",
+                        "yellow": "Yellow",
+                        "orange": "Orange",
+                        "red": "Red",
+                        "colour": "Colorful",
+                    },
+                },
+                {
+                    "name": "select_timer",
+                    "dps": TIMER_DP,
+                    "options": {
+                        "cancel": "Off",
+                        "2h": "2 hours",
+                        "4h": "4 hours",
+                        "6h": "6 hours",
+                        "8h": "8 hours",
+                        "10h": "10 hours",
+                        "12h": "12 hours",
+                    },
+                },
+            ]
+        )
+        self.mark_secondary(["select_light", "select_timer"])
+
+    def test_supported_features(self):
+        self.assertEqual(
+            self.subject.supported_features,
+            FanEntityFeature.SET_SPEED,
+        )
+
+    def test_speed(self):
+        self.dps[SPEED_DP] = "sleep"
+        self.assertEqual(self.subject.percentage, 10)
+        self.dps[SPEED_DP] = "grade1"
+        self.assertEqual(self.subject.percentage, 25)
+        self.dps[SPEED_DP] = "grade2"
+        self.assertEqual(self.subject.percentage, 40)
+        self.dps[SPEED_DP] = "grade3"
+        self.assertEqual(self.subject.percentage, 55)
+        self.dps[SPEED_DP] = "grade4"
+        self.assertEqual(self.subject.percentage, 70)
+        self.dps[SPEED_DP] = "grade5"
+        self.assertEqual(self.subject.percentage, 85)
+        self.dps[SPEED_DP] = "grade6"
+        self.assertEqual(self.subject.percentage, 100)
+
+    async def test_set_speed_snaps(self):
+        async with assert_device_properties_set(
+            self.subject._device,
+            {SPEED_DP: "grade3"},
+        ):
+            await self.subject.async_set_percentage(50)