Procházet zdrojové kódy

Add support for Avatto Blinds controller.

Issue #213
Jason Rumney před 3 roky
rodič
revize
904c3cec37

+ 1 - 1
ACKNOWLEDGEMENTS.md

@@ -104,6 +104,6 @@ Further device support has been made with the assistance of users.  Please consi
 - [RichardMawdsley](https://github.com/RichardMawdsley) for assistance supporting ElectriQ Airflex 15W heatpumps.
 - [fwelvering](https://github.com/fwelvering) for assistance supporting a second variant of W'eau pool heatpumps. 
 - [illuzn](https://github.com/illuzn) for contributing support for Kogan Tower Heaters.
-- [vnkorol](https://github.com/vnkorol) for assistance supporting 4-way power monitoring strip.
+- [vnkorol](https://github.com/vnkorol) for assistance supporting 4-way power monitoring strip and Avatto roller blinds.
 - [OmegaKill](https://github.com/OmegaKill) for assistance supporting Be Cool heatpumps.
 - [djusHa](https://github.com/djusHa) for contributing support for essentials portable air purifier.

+ 1 - 0
README.md

@@ -201,6 +201,7 @@ Other brands may work with the above configurations
 - Kogan Garage Door with tilt sensor
 - QS-WIFI-C01(BK) Curtain Module
 - M027 Curtain Module (sold under several brands, including zemismart, meterk and others)
+- Avatto Roller Blinds controller
 
 ### Vacuum Cleaners
 - Lefant M213 Vacuum Cleaner (also works for Lefant M213S and APOSEN A550)

+ 90 - 0
custom_components/tuya_local/devices/avatto_roller_blinds.yaml

@@ -0,0 +1,90 @@
+name: Avatto Roller Blinds
+product:
+  - id: 3r8gc33pnqsxfe1g
+primary_entity:
+  entity: cover
+  class: blind
+  dps:
+    - id: 1
+      name: control
+      type: string
+      mapping:
+        - dps_val: open
+          value: open
+        - dps_val: close
+          value: close
+        - dps_val: stop
+          value: stop
+    - id: 2
+      name: position
+      type: integer
+      range:
+        min: 0
+        max: 100
+    - id: 3
+      name: current_position
+      type: integer
+      unit: "%"
+      optional: true
+    - id: 5
+      name: control_back_mode
+      type: boolean
+    - id: 7
+      name: action
+      type: string
+      mapping:
+        - dps_val: opening
+          constraint: current_position
+          conditions:
+            - dps_val: 100
+              value: opened
+            - dps_val: null
+              value: opened
+            - value: opening
+        - dps_val: closing
+          constraint: current_position
+          conditions:
+            - dps_val: 0
+              value: closed
+            - dps_val: null
+              value: closed
+            - value: closing
+secondary_entities:
+  - entity: select
+    name: Timer
+    icon: "mdi:timer"
+    category: config
+    dps:
+      - id: 8
+        name: option
+        type: string
+        mapping:
+          - dps_val: cancel
+            value: "Off"
+          - dps_val: "1"
+            value: "1 hour"
+          - dps_val: "2"
+            value: "2 hours"
+          - dps_val: "3"
+            value: "3 hours"
+          - dps_val: "4"
+            value: "4 hours"
+  - entity: sensor
+    name: Timer
+    icon: "mdi:timer"
+    category: diagnostic
+    dps:
+      - id: 9
+        name: sensor
+        type: integer
+        optional: true
+        unit: s
+  - entity: sensor
+    name: Travel Time
+    icon: "mdi:hourglass"
+    category: diagnostic
+    dps:
+      - id: 11
+        name: sensor
+        type: integer
+        unit: ms

+ 11 - 0
tests/const.py

@@ -1463,3 +1463,14 @@ ESSENTIALS_PURIFIER_PAYLOAD = {
     "21": "good",
     "101": "Standard",
 }
+
+AVATTO_BLINDS_PAYLOAD = {
+    "1": "close",
+    "2": 0,
+    "3": 0,
+    "5": False,
+    "7": "closing",
+    "8": "cancel",
+    "9": 0,
+    "11": 0,
+}

+ 138 - 0
tests/devices/test_avatto_blinds.py

@@ -0,0 +1,138 @@
+"""Tests for the Avatto roller blinds controller."""
+from homeassistant.components.cover import (
+    CoverDeviceClass,
+    CoverEntityFeature,
+)
+from homeassistant.const import TIME_MILLISECONDS, TIME_SECONDS
+
+from ..const import AVATTO_BLINDS_PAYLOAD
+from ..helpers import assert_device_properties_set
+from ..mixins.sensor import MultiSensorTests
+from ..mixins.select import BasicSelectTests
+from .base_device_tests import TuyaDeviceTestCase
+
+COMMAND_DP = "1"
+POSITION_DP = "2"
+CURRENTPOS_DP = "3"
+BACK_DP = "5"
+ACTION_DP = "7"
+TIMER_DP = "8"
+COUNTDOWN_DP = "9"
+TRAVELTIME_DP = "11"
+
+
+class TestAvattoBlinds(MultiSensorTests, BasicSelectTests, TuyaDeviceTestCase):
+    __test__ = True
+
+    def setUp(self):
+        self.setUpForConfig("avatto_roller_blinds.yaml", AVATTO_BLINDS_PAYLOAD)
+        self.subject = self.entities["cover"]
+        self.setUpMultiSensors(
+            [
+                {
+                    "dps": TRAVELTIME_DP,
+                    "name": "sensor_travel_time",
+                    "min": 0,
+                    "max": 120000,
+                    "unit": TIME_MILLISECONDS,
+                },
+                {
+                    "dps": COUNTDOWN_DP,
+                    "name": "sensor_timer",
+                    "min": 0,
+                    "max": 86400,
+                    "unit": TIME_SECONDS,
+                },
+            ]
+        )
+        self.setUpBasicSelect(
+            TIMER_DP,
+            self.entities.get("select_timer"),
+            {
+                "cancel": "Off",
+                "1": "1 hour",
+                "2": "2 hours",
+                "3": "3 hours",
+                "4": "4 hours",
+            },
+        ),
+        self.mark_secondary(["sensor_travel_time", "sensor_timer", "select_timer"])
+
+    def test_device_class_is_blind(self):
+        self.assertEqual(self.subject.device_class, CoverDeviceClass.BLIND)
+
+    def test_supported_features(self):
+        self.assertEqual(
+            self.subject.supported_features,
+            (
+                CoverEntityFeature.OPEN
+                | CoverEntityFeature.CLOSE
+                | CoverEntityFeature.SET_POSITION
+                | CoverEntityFeature.STOP
+            ),
+        )
+
+    def test_current_cover_position(self):
+        self.dps[CURRENTPOS_DP] = 47
+        self.assertEqual(self.subject.current_cover_position, 47)
+
+    def test_is_opening(self):
+        self.dps[ACTION_DP] = "opening"
+        self.dps[CURRENTPOS_DP] = 100
+        self.assertFalse(self.subject.is_opening)
+        self.dps[CURRENTPOS_DP] = 50
+        self.assertTrue(self.subject.is_opening)
+        self.dps[ACTION_DP] = "closing"
+        self.assertFalse(self.subject.is_opening)
+        self.dps[ACTION_DP] = "opening"
+        self.dps[CURRENTPOS_DP] = None
+        self.assertFalse(self.subject.is_opening)
+
+    def test_is_closing(self):
+        self.dps[ACTION_DP] = "closing"
+        self.dps[CURRENTPOS_DP] = 0
+        self.assertFalse(self.subject.is_closing)
+        self.dps[CURRENTPOS_DP] = 50
+        self.assertTrue(self.subject.is_closing)
+        self.dps[ACTION_DP] = "opening"
+        self.assertFalse(self.subject.is_closing)
+        self.dps[ACTION_DP] = "closing"
+        self.dps[CURRENTPOS_DP] = None
+        self.assertFalse(self.subject.is_closing)
+
+    def test_is_closed(self):
+        self.dps[CURRENTPOS_DP] = 100
+        self.assertFalse(self.subject.is_closed)
+        self.dps[CURRENTPOS_DP] = 0
+        self.assertTrue(self.subject.is_closed)
+        self.dps[ACTION_DP] = "closing"
+        self.dps[CURRENTPOS_DP] = None
+        self.assertTrue(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()
+
+    async def test_set_cover_position(self):
+        async with assert_device_properties_set(
+            self.subject._device,
+            {POSITION_DP: 23},
+        ):
+            await self.subject.async_set_cover_position(23)