فهرست منبع

Implement tests for Digoo, Woox and simple switch with timer.

Issue #87, #91, PR #88
Jason Rumney 4 سال پیش
والد
کامیت
ac7fd295fd

+ 1 - 1
ACKNOWLEDGEMENTS.md

@@ -59,7 +59,7 @@ Further device support has been made with the assistance of users.  Please consi
  - [mvroosmalen1970](https://github.com/mvroosmalen1970) for assistance in supporting Eurom SaniWall 2000 heaters.
  - [petrkotek](https://github.com/petrkotek) for contributing support for Madimack Elite V3 pool heatpumps.
  - [irakhlin](https://github.com/irakhlin) for contributing support for Aspen ASP200 fans.
- - [vampywiz17](https://github.com/vampywiz17) for contributing support for TMWF02 fan controllers.
+ - [vampywiz17](https://github.com/vampywiz17) for contributing support for TMWF02 fan controllers, Digoo and Woox smartplugs and powerstrips and simple switches with timers.
  - [awaldram](https://github.com/awaldram) for confirming BHT-3000 support.
  - [bob-tm](https://github.com/bob-tm) for contributing support from Wetair WAW-H1210LW humidifiers.
  - [shakin89](https://github.com/shakin89) for assistance in supporting Beca BAC-002 thermostats.

+ 7 - 3
README.md

@@ -109,12 +109,16 @@ the device will not work despite being listed below.
 ### SmartPlugs/Wall sockets
 - Kogan Single Smartplug with Energy Monitoring
 - Kogan Single Smartplug with Energy Monitoring and USB charging
+- CBE Smart plug with advanced energy monitoring
+- Mirabella Genio Smart plug with USB
 - Grid Connect double outlet with Energy Monitoring, Master and Individual switches and Child Lock.
+- DIGOO DG-SP202 dual smartplug with energy monitoring and timers.
 - Grid Connect double outlet wall socket
-- Mirabella Genio Smart plug with USB
-- CBE Smart plug with advanced energy monitoring
-- Other brands may work with the above configurations
+- Woox R4028/DIGOO DG-PS01 3 outlet + USB powerstrip with individual timers.
+Other brands may work with the above configurations
+
 - Simple Switch - a switch only, can be a fallback for many other unsupported devices, to allow just power to be switched on/off.
+- Simple Switch with Timer - a single switch and timer, will probably work for a lot of smart switches that are not covered by the more advanced configs above.
 
 ### Covers
 - Simple Garage Door

+ 3 - 2
custom_components/tuya_local/devices/digoo_dgsp202.yaml

@@ -1,7 +1,8 @@
 name: DIGOO DG-SP202
 primary_entity:
   entity: switch
-  class: outlet 1
+  class: outlet
+  name: outlet 1
   dps:
     - id: 1
       type: boolean
@@ -15,7 +16,7 @@ primary_entity:
 secondary_entities:
   - entity: switch
     name: outlet 2
-    class: switch
+    class: outlet
     dps:
       - id: 2
         type: boolean

+ 1 - 0
custom_components/tuya_local/devices/simple_switch_timer.yaml

@@ -1,6 +1,7 @@
 name: Simple Switch With Timer
 primary_entity:
   entity: switch
+  class: outlet
   dps:
     - id: 1
       name: switch

+ 8 - 4
custom_components/tuya_local/devices/woox_r4028_powerstrip.yaml

@@ -1,8 +1,8 @@
-name: Woox R4028 + DIGOO DG-PS01
+name: 3 outlet + USB powerstrip
 primary_entity:
   entity: switch
   name: outlet 1
-  class: switch
+  class: outlet
   dps:
     - id: 1
       type: boolean
@@ -10,14 +10,14 @@ primary_entity:
 secondary_entities:
   - entity: switch
     name: outlet 2
-    class: switch
+    class: outlet
     dps:
       - id: 2
         type: boolean
         name: switch
   - entity: switch
     name: outlet 3
-    class: switch
+    class: outlet
     dps:
       - id: 3
         type: boolean
@@ -32,6 +32,7 @@ secondary_entities:
   - entity: number
     category: config
     name: Timer 1
+    icon: "mdi:timer"
     dps:
       - id: 101
         name: value
@@ -45,6 +46,7 @@ secondary_entities:
   - entity: number
     category: config
     name: Timer 2
+    icon: "mdi:timer"
     dps:
       - id: 102
         name: value
@@ -58,6 +60,7 @@ secondary_entities:
   - entity: number
     category: config
     name: Timer 3
+    icon: "mdi:timer"
     dps:
       - id: 103
         name: value
@@ -71,6 +74,7 @@ secondary_entities:
   - entity: number
     category: config
     name: USB Timer
+    icon: "mdi:timer"
     dps:
       - id: 105
         name: value

+ 26 - 0
tests/const.py

@@ -706,3 +706,29 @@ TMWF02_FAN_PAYLOAD = {
     "3": "level_2",
     "4": 40,
 }
+
+TIMED_SOCKET_PAYLOAD = {
+    "1": True,
+    "11": 0,
+}
+
+DIGOO_DGSP202_SOCKET_PAYLOAD = {
+    "1": True,
+    "2": True,
+    "9": 0,
+    "10": 0,
+    "18": 500,
+    "19": 1200,
+    "20": 240,
+}
+
+WOOX_R4028_SOCKET_PAYLOAD = {
+    "1": True,
+    "2": True,
+    "3": True,
+    "7": True,
+    "101": 0,
+    "102": 0,
+    "103": 0,
+    "105": 0,
+}

+ 16 - 2
tests/mixins/switch.py

@@ -108,7 +108,13 @@ class BasicSwitchTests:
             )
 
     def test_basic_switch_state_attributes(self):
-        self.assertEqual(self.basicSwitch.device_state_attributes, {})
+        if self.basicSwitchPowerDps is None:
+            self.assertEqual(self.basicSwitch.device_state_attributes, {})
+        else:
+            self.dps[self.basicSwitchPowerDps] = 99 * self.basicSwitchPowerScale
+            self.assertDictEqual(
+                self.basicSwitch.device_state_attributes, {"current_power_w": 99.0}
+            )
 
 
 class MultiSwitchTests:
@@ -195,4 +201,12 @@ class MultiSwitchTests:
     def test_multi_switch_state_attributes(self):
         for key, subject in self.multiSwitch.items():
             with self.subTest(key):
-                self.assertEqual(subject.device_state_attributes, {})
+                dp = self.multiSwitchPowerDps.get(key)
+                if dp is None:
+                    self.assertEqual(subject.device_state_attributes, {})
+                else:
+                    self.dps[dp] = 987 * self.multiSwitchPowerScale.get(key, 1)
+                    self.assertDictEqual(
+                        subject.device_state_attributes,
+                        {"current_power_w": 987.0},
+                    )