From bf23f73cced59946f3a7fb2a9573f616b31b309e Mon Sep 17 00:00:00 2001
From: "Steven B." <51370195+sdb9696@users.noreply.github.com>
Date: Tue, 19 Nov 2024 23:36:16 +0000
Subject: [PATCH] Extend dump_devinfo iot queries (#1278)

---
 devtools/dump_devinfo.py                | 17 ++++-
 tests/fakeprotocol_iot.py               |  5 +-
 tests/fixtures/KP105(UK)_1.0_1.0.5.json | 89 +++++++++++++++++++++++--
 3 files changed, 101 insertions(+), 10 deletions(-)

diff --git a/devtools/dump_devinfo.py b/devtools/dump_devinfo.py
index 13c597e0..d69c8c7e 100644
--- a/devtools/dump_devinfo.py
+++ b/devtools/dump_devinfo.py
@@ -114,6 +114,7 @@ def scrub(res):
         "connect_ssid",
         "encrypt_info",
         "local_ip",
+        "username",
     ]
 
     for k, v in res.items():
@@ -152,7 +153,7 @@ def scrub(res):
                     v = base64.b64encode(b"#MASKED_SSID#").decode()
                 elif k in ["nickname"]:
                     v = base64.b64encode(b"#MASKED_NAME#").decode()
-                elif k in ["alias", "device_alias", "device_name"]:
+                elif k in ["alias", "device_alias", "device_name", "username"]:
                     v = "#MASKED_NAME#"
                 elif isinstance(res[k], int):
                     v = 0
@@ -398,11 +399,25 @@ async def get_legacy_fixture(
     items = [
         Call(module="system", method="get_sysinfo"),
         Call(module="emeter", method="get_realtime"),
+        Call(module="cnCloud", method="get_info"),
+        Call(module="cnCloud", method="get_intl_fw_list"),
+        Call(module="smartlife.iot.common.schedule", method="get_next_action"),
+        Call(module="smartlife.iot.common.schedule", method="get_rules"),
+        Call(module="schedule", method="get_next_action"),
+        Call(module="schedule", method="get_rules"),
         Call(module="smartlife.iot.dimmer", method="get_dimmer_parameters"),
+        Call(module="smartlife.iot.dimmer", method="get_default_behavior"),
         Call(module="smartlife.iot.common.emeter", method="get_realtime"),
         Call(
             module="smartlife.iot.smartbulb.lightingservice", method="get_light_state"
         ),
+        Call(
+            module="smartlife.iot.smartbulb.lightingservice",
+            method="get_default_behavior",
+        ),
+        Call(
+            module="smartlife.iot.smartbulb.lightingservice", method="get_light_details"
+        ),
         Call(module="smartlife.iot.LAS", method="get_config"),
         Call(module="smartlife.iot.LAS", method="get_current_brt"),
         Call(module="smartlife.iot.PIR", method="get_config"),
diff --git a/tests/fakeprotocol_iot.py b/tests/fakeprotocol_iot.py
index b03564d1..8c4e4057 100644
--- a/tests/fakeprotocol_iot.py
+++ b/tests/fakeprotocol_iot.py
@@ -213,8 +213,9 @@ class FakeIotTransport(BaseTransport):
         for target in info:
             if target != "discovery_result":
                 for cmd in info[target]:
-                    # print("initializing tgt %s cmd %s" % (target, cmd))
-                    proto[target][cmd] = info[target][cmd]
+                    # Use setdefault in case the fixture has modules not yet
+                    # part of the baseproto.
+                    proto.setdefault(target, {})[cmd] = info[target][cmd]
 
         # if we have emeter support, we need to add the missing pieces
         for module in ["emeter", "smartlife.iot.common.emeter"]:
diff --git a/tests/fixtures/KP105(UK)_1.0_1.0.5.json b/tests/fixtures/KP105(UK)_1.0_1.0.5.json
index 71ec3b7b..ce194375 100644
--- a/tests/fixtures/KP105(UK)_1.0_1.0.5.json
+++ b/tests/fixtures/KP105(UK)_1.0_1.0.5.json
@@ -1,7 +1,82 @@
 {
+    "cnCloud": {
+        "get_info": {
+            "binded": 1,
+            "cld_connection": 0,
+            "err_code": 0,
+            "fwDlPage": "",
+            "fwNotifyType": -1,
+            "illegalType": 0,
+            "server": "n-devs.tplinkcloud.com",
+            "stopConnect": 0,
+            "tcspInfo": "",
+            "tcspStatus": 1,
+            "username": "#MASKED_NAME#"
+        },
+        "get_intl_fw_list": {
+            "err_code": -7,
+            "err_msg": "unknown error"
+        }
+    },
+    "schedule": {
+        "get_next_action": {
+            "action": 1,
+            "err_code": 0,
+            "id": "0794F4729DB271627D1CF35A9A854030",
+            "schd_time": 68927,
+            "type": 2
+        },
+        "get_rules": {
+            "enable": 1,
+            "err_code": 0,
+            "rule_list": [
+                {
+                    "eact": -1,
+                    "enable": 1,
+                    "id": "8AA75A50A8440B17941D192BD9E01FFA",
+                    "name": "name",
+                    "repeat": 1,
+                    "sact": 1,
+                    "smin": 1027,
+                    "soffset": 0,
+                    "stime_opt": 2,
+                    "wday": [
+                        1,
+                        1,
+                        1,
+                        1,
+                        1,
+                        1,
+                        1
+                    ]
+                },
+                {
+                    "eact": -1,
+                    "enable": 1,
+                    "id": "9F62073CF69D8645173412283AD63A2C",
+                    "name": "name",
+                    "repeat": 1,
+                    "sact": 0,
+                    "smin": 504,
+                    "soffset": 0,
+                    "stime_opt": 1,
+                    "wday": [
+                        1,
+                        1,
+                        1,
+                        1,
+                        1,
+                        1,
+                        1
+                    ]
+                }
+            ],
+            "version": 2
+        }
+    },
     "system": {
         "get_sysinfo": {
-            "active_mode": "schedule",
+            "active_mode": "count_down",
             "alias": "#MASKED_NAME#",
             "dev_name": "Smart Wi-Fi Plug",
             "deviceId": "0000000000000000000000000000000000000000",
@@ -18,16 +93,16 @@
             "model": "KP105(UK)",
             "next_action": {
                 "action": 1,
-                "id": "8AA75A50A8440B17941D192BD9E01FFA",
-                "schd_sec": 59160,
-                "type": 1
+                "id": "0794F4729DB271627D1CF35A9A854030",
+                "schd_sec": 68927,
+                "type": 2
             },
             "ntc_state": 0,
             "obd_src": "tplink",
             "oemId": "00000000000000000000000000000000",
-            "on_time": 0,
-            "relay_state": 0,
-            "rssi": -66,
+            "on_time": 7138,
+            "relay_state": 1,
+            "rssi": -77,
             "status": "configured",
             "sw_ver": "1.0.5 Build 191209 Rel.094735",
             "updating": 0