浏览代码

Avatto curtain: use cover entity instead of buttons/select.

As confirmed with loratap, the cover is working now with this minimalist
control-only dp layout.

Issue #378
Jason Rumney 3 年之前
父节点
当前提交
8c1b59f40d

+ 8 - 40
custom_components/tuya_local/devices/avatto_curtain_switch.yaml

@@ -1,36 +1,19 @@
 name: Avatto curtain switch
 primary_entity:
-  entity: button
-  name: stop
-  icon: "mdi:pause-octagon"
+  entity: cover
+  class: curtain
   dps:
     - id: 1
-      name: button
+      name: control
       type: string
       mapping:
+        - dps_val: open
+          value: open
+        - dps_val: close
+          value: close
         - dps_val: stop
-          value: true
+          value: stop
 secondary_entities:
-  - entity: button
-    name: open
-    icon: "mdi:curtains"
-    dps:
-      - id: 1
-        name: button
-        type: string
-        mapping:
-          - dps_val: open
-            value: true
-  - entity: button
-    name: close
-    icon: "mdi:curtains-closed"
-    dps:
-      - id: 1
-        name: button
-        type: string
-        mapping:
-          - dps_val: close
-            value: true
   - entity: light
     category: config
     name: Backlight
@@ -38,18 +21,3 @@ secondary_entities:
       - id: 101
         type: boolean
         name: switch
-  - entity: select
-    deprecated: button
-    category: config
-    icon: "mdi:curtains"
-    dps:
-      - id: 1
-        name: option
-        type: string
-        mapping:
-          - dps_val: open
-            value: Open
-          - dps_val: close
-            value: Close
-          - dps_val: stop
-            value: Stop

+ 50 - 34
tests/devices/test_avatto_curtain_switch.py

@@ -1,53 +1,69 @@
 """Tests for the Avatto roller blinds controller."""
+from homeassistant.components.cover import CoverDeviceClass, CoverEntityFeature
 
 from ..const import AVATTO_CURTAIN_PAYLOAD
 from ..helpers import assert_device_properties_set
 from ..mixins.light import BasicLightTests
-from ..mixins.select import BasicSelectTests
-from ..mixins.button import MultiButtonTests
 from .base_device_tests import TuyaDeviceTestCase
 
 COMMAND_DP = "1"
 BACKLIGHT_DP = "101"
 
 
-class TestAvattoCurtainSwitch(
-    MultiButtonTests, BasicSelectTests, BasicLightTests, TuyaDeviceTestCase
-):
+class TestAvattoCurtainSwitch(BasicLightTests, TuyaDeviceTestCase):
     __test__ = True
 
     def setUp(self):
-        self.setUpForConfig("avatto_curtain_switch.yaml", AVATTO_CURTAIN_PAYLOAD)
-        self.setUpMultiButtons(
-            [
-                {
-                    "dps": COMMAND_DP,
-                    "name": "button_stop",
-                    "testdata": "stop",
-                },
-                {
-                    "dps": COMMAND_DP,
-                    "name": "button_open",
-                    "testdata": "open",
-                },
-                {
-                    "dps": COMMAND_DP,
-                    "name": "button_close",
-                    "testdata": "close",
-                },
-            ]
+        self.setUpForConfig(
+            "avatto_curtain_switch.yaml",
+            AVATTO_CURTAIN_PAYLOAD,
         )
-        self.setUpBasicSelect(
-            COMMAND_DP,
-            self.entities.get("select"),
-            {
-                "stop": "Stop",
-                "open": "Open",
-                "close": "Close",
-            },
-        ),
+        self.subject = self.entities.get("cover")
         self.setUpBasicLight(
             BACKLIGHT_DP,
             self.entities.get("light_backlight"),
         )
-        self.mark_secondary(["select", "light_backlight"])
+        self.mark_secondary(["light_backlight"])
+
+    def test_device_class_is_curtain(self):
+        self.assertEqual(self.subject.device_class, CoverDeviceClass.CURTAIN)
+
+    def test_supported_features(self):
+        self.assertEqual(
+            self.subject.supported_features,
+            (
+                CoverEntityFeature.OPEN
+                | CoverEntityFeature.CLOSE
+                | CoverEntityFeature.STOP
+            ),
+        )
+
+    def test_is_opening(self):
+        self.assertIsNone(self.subject.is_opening)
+
+    def test_is_closing(self):
+        self.assertIsNone(self.subject.is_closing)
+
+    def test_is_closed(self):
+        self.assertIsNone(self.subject.is_closed)
+
+    async def test_open_cover(self):
+        async with assert_device_properties_set(
+            self.subject._device,
+            {COMMAND_DP: "open"},
+        ):
+            await self.subject.async_open_cover()
+
+    async def test_close_cover(self):
+        async with assert_device_properties_set(
+            self.subject._device,
+            {COMMAND_DP: "close"},
+        ):
+            await self.subject.async_close_cover()
+
+    async def test_stop_cover(self):
+        async with assert_device_properties_set(
+            self.subject._device,
+            {COMMAND_DP: "stop"},
+        ):
+            await self.subject.async_stop_cover()

+ 2 - 28
tests/test_button.py

@@ -15,39 +15,13 @@ from custom_components.tuya_local.button import (
 )
 
 
-@pytest.mark.asyncio
-async def test_init_entry(hass):
-    """Test the initialisation."""
-    entry = MockConfigEntry(
-        domain=DOMAIN,
-        data={
-            CONF_TYPE: "avatto_curtain_switch",
-            CONF_DEVICE_ID: "dummy",
-            CONF_PROTOCOL_VERSION: "auto",
-        },
-    )
-    # although async, the async_add_entities function passed to
-    # async_setup_entry is called truly asynchronously. If we use
-    # AsyncMock, it expects us to await the result.
-    m_add_entities = Mock()
-    m_device = AsyncMock()
-
-    hass.data[DOMAIN] = {}
-    hass.data[DOMAIN]["dummy"] = {}
-    hass.data[DOMAIN]["dummy"]["device"] = m_device
-
-    await async_setup_entry(hass, entry, m_add_entities)
-    assert type(hass.data[DOMAIN]["dummy"]["button_stop"]) == TuyaLocalButton
-    m_add_entities.assert_called_once()
-
-
 @pytest.mark.asyncio
 async def test_init_entry_as_secondary(hass):
     """Test the initialisation."""
     entry = MockConfigEntry(
         domain=DOMAIN,
         data={
-            CONF_TYPE: "avatto_curtain_switch",
+            CONF_TYPE: "catit_pet_feeder",
             CONF_DEVICE_ID: "dummy",
             CONF_PROTOCOL_VERSION: "auto",
         },
@@ -63,7 +37,7 @@ async def test_init_entry_as_secondary(hass):
     hass.data[DOMAIN]["dummy"]["device"] = m_device
 
     await async_setup_entry(hass, entry, m_add_entities)
-    assert type(hass.data[DOMAIN]["dummy"]["button_open"]) == TuyaLocalButton
+    assert type(hass.data[DOMAIN]["dummy"]["button_factory_reset"]) == TuyaLocalButton
     m_add_entities.assert_called_once()