Răsfoiți Sursa

New model Kogan switch also has timer on a different DPS.

Issue #2: The timer on newer Kogan switches is on DPS "9" rather than "2".
Additionally there are values on DPS "21", "22", "23", "24", "25".

There appear to be other brands of switches using the same DPS layout, and
the schemas for these list 21 as a test mode, and the others as calibration
values.
Jason Rumney 5 ani în urmă
părinte
comite
4b62dd76dc

+ 2 - 0
custom_components/tuya_local/kogan_socket/const.py

@@ -4,6 +4,7 @@ ATTR_SWITCH = "switch"
 ATTR_TIMER = "timer"
 ATTR_CURRENT_A = "current_a"
 ATTR_VOLTAGE_V = "voltage_v"
+ATTR_ALT_TIMER = "alt_timer"
 ATTR_ALT_CURRENT_A = "alt_currrent_a"
 ATTR_ALT_CURRENT_POWER_W = "alt_power_w"
 ATTR_ALT_VOLTAGE_V = "alt_voltage_v"
@@ -14,6 +15,7 @@ PROPERTY_TO_DPS_ID = {
     ATTR_CURRENT_A: "4",
     ATTR_CURRENT_POWER_W: "5",
     ATTR_VOLTAGE_V: "6",
+    ATTR_ALT_TIMER: "9",
     ATTR_ALT_CURRENT_A: "18",
     ATTR_ALT_CURRENT_POWER_W: "19",
     ATTR_ALT_VOLTAGE_V: "20",

+ 4 - 0
custom_components/tuya_local/kogan_socket/switch.py

@@ -14,6 +14,7 @@ from .const import (
     ATTR_SWITCH,
     ATTR_TIMER,
     ATTR_VOLTAGE_V,
+    ATTR_ALT_TIMER,
     ATTR_ALT_CURRENT_A,
     ATTR_ALT_CURRENT_POWER_W,
     ATTR_ALT_VOLTAGE_V,
@@ -86,6 +87,9 @@ class KoganSocketSwitch(SwitchEntity):
         current = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_CURRENT_A])
 
         # Some newer plugs have the measurements on different DPS ids
+        if timer is None:
+            timer = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_ALT_TIMER])
+
         if voltage is None:
             voltage = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_ALT_VOLTAGE_V])
 

+ 3 - 1
tests/const.py

@@ -51,6 +51,7 @@ KOGAN_SOCKET_PAYLOAD = {
     "4": 200,
     "5": 460,
     "6": 2300,
+    "9": None,
     "18": None,
     "19": None,
     "20": None,
@@ -58,10 +59,11 @@ KOGAN_SOCKET_PAYLOAD = {
 
 KOGAN_SOCKET_PAYLOAD2 = {
     "1": True,
-    "2": 0,
+    "2": None,
     "4": None,
     "5": None,
     "6": None,
+    "9": 0,
     "18": 200,
     "19": 460,
     "20": 2300,

+ 3 - 2
tests/kogan_socket/test_alt_switch.py

@@ -7,6 +7,7 @@ from homeassistant.const import STATE_UNAVAILABLE
 from custom_components.tuya_local.kogan_socket.const import (
     ATTR_SWITCH,
     ATTR_TIMER,
+    ATTR_ALT_TIMER,
     ATTR_ALT_CURRENT_A,
     ATTR_ALT_CURRENT_POWER_W,
     ATTR_ALT_VOLTAGE_V,
@@ -92,7 +93,7 @@ class TestKoganSocket(IsolatedAsyncioTestCase):
         self.assertEqual(self.subject.current_power_w, STATE_UNAVAILABLE)
 
     def test_device_state_attributes_set(self):
-        self.dps[PROPERTY_TO_DPS_ID[ATTR_TIMER]] = 1
+        self.dps[PROPERTY_TO_DPS_ID[ATTR_ALT_TIMER]] = 1
         self.dps[PROPERTY_TO_DPS_ID[ATTR_ALT_VOLTAGE_V]] = 2350
         self.dps[PROPERTY_TO_DPS_ID[ATTR_ALT_CURRENT_A]] = 1234
         self.dps[PROPERTY_TO_DPS_ID[ATTR_ALT_CURRENT_POWER_W]] = 5678
@@ -106,7 +107,7 @@ class TestKoganSocket(IsolatedAsyncioTestCase):
             },
         )
 
-        self.dps[PROPERTY_TO_DPS_ID[ATTR_TIMER]] = 0
+        self.dps[PROPERTY_TO_DPS_ID[ATTR_ALT_TIMER]] = 0
         self.dps[PROPERTY_TO_DPS_ID[ATTR_ALT_VOLTAGE_V]] = None
         self.dps[PROPERTY_TO_DPS_ID[ATTR_ALT_CURRENT_A]] = None
         self.dps[PROPERTY_TO_DPS_ID[ATTR_ALT_CURRENT_POWER_W]] = None