Browse Source

smartplugv2_energy: add switch for Overcharge Cutoff feature.

Jason Rumney 4 years ago
parent
commit
254cb4a099

+ 10 - 3
custom_components/tuya_local/devices/smartplugv2_energy.yaml

@@ -30,13 +30,11 @@ primary_entity:
     - id: 42
       type: string
       name: random_timer
-    - id: 46
-      type: boolean
-      name: unknown_46
 secondary_entities:
   - entity: number
     category: config
     name: Timer
+    icon: "mdi:timer"
     dps:
       - id: 9
         type: integer
@@ -103,6 +101,7 @@ secondary_entities:
   - entity: select
     category: config
     name: Initial State
+    icon: "mdi:toggle-switch"
     dps:
       - id: 38
         type: string
@@ -114,3 +113,11 @@ secondary_entities:
             value: "Off"
           - dps_val: memory
             value: "Last State"
+  - entity: switch
+    name: Overcharge Cutoff
+    category: config
+    icon: "mdi:battery-charging"
+    dps:
+      - id: 46
+        type: boolean
+        name: switch

+ 2 - 0
custom_components/tuya_local/translations/en.json

@@ -92,6 +92,7 @@
 		    "switch_open_window_detector": "Include open window detect as a switch entity",
 		    "switch_outlet_1": "Include outlet 1 as a switch entity",
 		    "switch_outlet_2": "Include outlet 2 as a switch entity",
+		    "switch_overcharge_cutoff": "Include overcharge cutoff as a switch entity",
 		    "switch_sleep": "Include sleep mode as a switch entity",
 		    "switch_sound": "Include sound mute as a switch entity",
 		    "switch_uv_sterilization": "Include UV sterilization as a switch"
@@ -183,6 +184,7 @@
 		    "switch_open_window_detector": "Include open window detect as a switch entity",
 		    "switch_outlet_1": "Include outlet 1 as a switch entity",
 		    "switch_outlet_2": "Include outlet 2 as a switch entity",
+		    "switch_overcharge_cutoff": "Include overcharge cutoff as a switch entity",
 		    "switch_sleep": "Include sleep mode as a switch entity",
 		    "switch_sound": "Include sound mute as a switch entity",
 		    "switch_uv_sterilization": "Include UV sterilization as a switch"

+ 17 - 11
tests/devices/test_smartplugv2_energy.py

@@ -17,7 +17,7 @@ from ..mixins.binary_sensor import BasicBinarySensorTests
 from ..mixins.number import BasicNumberTests
 from ..mixins.select import BasicSelectTests
 from ..mixins.sensor import MultiSensorTests
-from ..mixins.switch import BasicSwitchTests
+from ..mixins.switch import MultiSwitchTests
 from .base_device_tests import TuyaDeviceTestCase
 
 SWITCH_DPS = "1"
@@ -35,7 +35,7 @@ ERROR_DPS = "26"
 INITIAL_DPS = "38"
 CYCLE_DPS = "41"
 RANDOM_DPS = "42"
-UNKNOWN46_DPS = "46"
+OVERCHARGE_DPS = "46"
 
 
 class TestSwitchV2Energy(
@@ -43,17 +43,25 @@ class TestSwitchV2Energy(
     BasicNumberTests,
     BasicSelectTests,
     MultiSensorTests,
-    BasicSwitchTests,
+    MultiSwitchTests,
     TuyaDeviceTestCase,
 ):
     __test__ = True
 
     def setUp(self):
         self.setUpForConfig("smartplugv2_energy.yaml", SMARTSWITCH_ENERGY_PAYLOAD)
-        self.setUpBasicSwitch(
-            SWITCH_DPS,
-            self.entities.get("switch"),
-            device_class=DEVICE_CLASS_OUTLET,
+        self.setUpMultiSwitch(
+            [
+                {
+                    "name": "switch",
+                    "dps": SWITCH_DPS,
+                    "device_class": DEVICE_CLASS_OUTLET,
+                },
+                {
+                    "name": "switch_overcharge_cutoff",
+                    "dps": OVERCHARGE_DPS,
+                },
+            ]
         )
         self.setUpBasicBinarySensor(
             ERROR_DPS,
@@ -106,7 +114,7 @@ class TestSwitchV2Energy(
             ]
         )
 
-    def test_basic_switch_state_attributes(self):
+    def test_multi_switch_state_attributes(self):
         self.dps[TEST_DPS] = 21
         self.dps[CALIBV_DPS] = 22
         self.dps[CALIBI_DPS] = 23
@@ -115,10 +123,9 @@ class TestSwitchV2Energy(
         self.dps[ERROR_DPS] = 26
         self.dps[CYCLE_DPS] = "1A2B"
         self.dps[RANDOM_DPS] = "3C4D"
-        self.dps[UNKNOWN46_DPS] = True
 
         self.assertDictEqual(
-            self.basicSwitch.device_state_attributes,
+            self.multiSwitch["switch"].device_state_attributes,
             {
                 "test_bit": 21,
                 "voltage_calibration": 22,
@@ -128,6 +135,5 @@ class TestSwitchV2Energy(
                 "fault_code": 26,
                 "cycle_timer": "1A2B",
                 "random_timer": "3C4D",
-                "unknown_46": True,
             },
         )