8000 Add new methods to dump_devinfo (#1373) · python-kasa/python-kasa@d03a387 · GitHub
[go: up one dir, main page]

Skip to content

Commit d03a387

Browse files
authored
Add new methods to dump_devinfo (#1373)
Adds `getMatterSetupInfo`, `getConnectStatus` and `scanApList`
1 parent e206d9b commit d03a387

File tree

5 files changed

+203
-48
lines changed

5 files changed

+203
-48
lines changed

devtools/helpers/smartcamrequests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,7 @@
6060
{"get": {"motor": {"name": ["capability"]}}},
6161
{"get": {"audio_capability": {"name": ["device_speaker", "device_microphone"]}}},
6262
{"get": {"audio_config": {"name": ["speaker", "microphone"]}}},
63+
{"getMatterSetupInfo": {"matter": {}}},
64+
{"getConnectStatus": {"onboarding": {"get_connect_status": {}}}},
65+
{"scanApList": {"onboarding": {"scan": {}}}},
6366
]

kasa/protocols/smartprotocol.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
"bssid": lambda _: "000000000000",
5151
"channel": lambda _: 0,
5252
"oem_id": lambda x: "REDACTED_" + x[9::],
53+
"hw_id": lambda x: "REDACTED_" + x[9::],
54+
"fw_id": lambda x: "REDACTED_" + x[9::],
5355
"setup_code": lambda x: re.sub(r"\w", "0", x), # matter
5456
"setup_payload": lambda x: re.sub(r"\w", "0", x), # matter
5557
"mfi_setup_code": lambda x: re.sub(r"\w", "0", x), # mfi_ for homekit
@@ -183,18 +185,18 @@ async def _execute_multiple_query(self, requests: dict, retry_count: int) -> dic
183185
multi_result: dict[str, Any] = {}
184186
smart_method = "multipleRequest"
185187

188+
end = len(requests)
189+
# The SmartCamProtocol sends requests with a length 1 as a
190+
# multipleRequest. The SmartProtocol doesn't so will never
191+
# raise_on_error
192+
raise_on_error = end == 1
193+
186194
multi_requests = [
187195
{"method": method, "params": params} if params else {"method": method}
188196
for method, params in requests.items()
189197
if method not in FORCE_SINGLE_REQUEST
190198
]
191199

192-
end = len(multi_requests)
193-
# The SmartCamProtocol sends requests with a length 1 as a
194-
# multipleRequest. The SmartProtocol doesn't so will never
195-
# raise_on_error
196-
raise_on_error = end == 1
197-
198200
# Break the requests down as there can be a size limit
199201
step = self._multi_request_batch_size
200202
if step == 1:
@@ -285,7 +287,9 @@ async def _execute_multiple_query(self, requests: dict, retry_count: int) -> dic
285287
resp = await self._transport.send(
286288
self.get_smart_request(method, params)
287289
)
288-
self._handle_response_error_code(resp, method, raise_on_error=False)
290+
self._handle_response_error_code(
291+
resp, method, raise_on_error=raise_on_error
292+
)
289293
multi_result[method] = resp.get("result")
290294
return multi_result
291295

tests/fakeprotocol_smartcam.py

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -221,35 +221,38 @@ async def _send_request(self, request_dict: dict):
221221
return {**result, "error_code": 0}
222222
else:
223223
return {"error_code": -1}
224-
elif method[:3] == "get":
224+
225+
if method in info:
225226
params = request_dict.get("params")
226-
if method in info:
227-
result = copy.deepcopy(info[method])
228-
if "start_index" in result and "sum" in result:
229-
list_key = next(
230-
iter([key for key in result if isinstance(result[key], list)])
231-
)
232-
start_index = (
233-
start_index
234-
if (params and (start_index := params.get("start_index")))
235-
else 0
236-
)
237-
238-
result[list_key] = result[list_key][
239-
start_index : start_index + self.list_return_size
240-
]
241-
return {"result": result, "error_code": 0}
242-
if (
243-
# FIXTURE_MISSING is for service calls not in place when
244-
# SMART fixtures started to be generated
245-
missing_result := self.FIXTURE_MISSING_MAP.get(method)
246-
) and missing_result[0] in self.components:
247-
# Copy to info so it will work with update methods
248-
info[method] = copy.deepcopy(missing_result[1])
249-
result = copy.deepcopy(info[method])
250-
return {"result": result, "error_code": 0}
227+
result = copy.deepcopy(info[method])
228+
if "start_index" in result and "sum" in result:
229+
list_key = next(
230+
iter([key for key in result if isinstance(result[key], list)])
231+
)
232+
start_index = (
233+
start_index
234+
if (params and (start_index := params.get("start_index")))
235+
else 0
236+
)
237+
238+
result[list_key] = result[list_key][
239+
start_index : start_index + self.list_return_size
240+
]
241+
return {"result": result, "error_code": 0}
251242

243+
if self.verbatim:
252244
return {"error_code": -1}
245+
246+
if (
247+
# FIXTURE_MISSING is for service calls not in place when
248+
# SMART fixtures started to be generated
249+
missing_result := self.FIXTURE_MISSING_MAP.get(method)
250+
) and missing_result[0] in self.components:
251+
# Copy to info so it will work with update methods
252+
info[method] = copy.deepcopy(missing_result[1])
253+
result = copy.deepcopy(info[method])
254+
return {"result": result, "error_code": 0}
255+
253256
return {"error_code": -1}
254257

255258
async def close(self) -> None:

tests/fixtures/smartcam/C210(EU)_2.0_1.4.3.json

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"connect_type": "wireless",
88
"device_id": "0000000000000000000000000000000000000000",
99
"http_port": 443,
10-
"last_alarm_time": "0",
11-
"last_alarm_type": "",
10+
"last_alarm_time": "1733422805",
11+
"last_alarm_type": "motion",
1212
"owner": "00000000000000000000000000000000",
1313
"sd_status": "offline"
1414
},
@@ -32,7 +32,8 @@
3232
"mac": "40-AE-30-00-00-00",
3333
"mgt_encrypt_schm": {
3434
"is_support_https": true
35-
}
35+
},
36+
"protocol_version": 1
3637
}
3738
},
3839
"getAlertConfig": {
@@ -266,15 +267,22 @@
266267
"getClockStatus": {
267268
"system": {
268269
"clock_status": {
269-
"local_time": "2024-11-01 13:58:50",
270-
"seconds_from_1970": 1730469530
270+
"local_time": "2024-12-15 11:28:40",
271+
"seconds_from_1970": 1734262120
272+
}
273+
}
274+
},
275+
"getConnectStatus": {
276+
"onboarding": {
277+
"get_connect_status": {
278+
"status": 0
271279
}
272280
}
273281
},
274282
"getConnectionType": {
275283
"link_type": "wifi",
276284
"rssi": "3",
277-
"rssiValue": -57,
285+
"rssiValue": -61,
278286
"ssid": "I01BU0tFRF9TU0lEIw=="
279287
},
280288
"getDetectionConfig": {
@@ -321,7 +329,7 @@
321329
"getFirmwareAutoUpgradeConfig": {
322330
"auto_upgrade": {
323331
"common": {
324-
"enabled": "on",
332+
"enabled": "off",
325333
"random_range": "120",
326334
"time": "03:00"
327335
}
@@ -338,8 +346,8 @@
338346
"getLastAlarmInfo": {
339347
"system": {
340348
"last_alarm_info": {
341-
"last_alarm_time": "0",
342-
"last_alarm_type": ""
349+
"last_alarm_time": "1733422805",
350+
"last_alarm_type": "motion"
343351
}
344352
}
345353
},
@@ -961,5 +969,35 @@
961969
}
962970
}
963971
}
972+
},
973+
"scanApList": {
974+
"onboarding": {
975+
"scan": {
976+
"ap_list": [
977+
{
978+
"auth": 4,
979+
"bssid": "000000000000",
980+
"encryption": 3,
981+
"rssi": 2,
982+
"ssid": "I01BU0tFRF9TU0lEIw=="
983+
},
984+
{
985+
"auth": 4,
986+
"bssid": "000000000000",
987+
"encryption": 3,
988+
"rssi": 1,
989+
"ssid": "I01BU0tFRF9TU0lEIw=="
990+
},
991+
{
992+
"auth": 4,
993+
"bssid": "000000000000",
994+
"encryption": 3,
995+
"rssi": 0,
996+
"ssid": "I01BU0tFRF9TU0lEIw=="
997+
}
998+
],
999+
"wpa3_supported": "false"
1000+
}
1001+
}
9641002
}
9651003
}

tests/fixtures/smartcam/H200(EU)_1.0_1.3.2.json

Lines changed: 113 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"firmware_version": "1.3.2 Build 20240424 rel.75425",
2727
"hardware_version": "1.0",
2828
"ip": "127.0.0.123",
29+
"isResetWiFi": false,
2930
"is_support_iot_cloud": true,
3031
"mac": "A8-6E-84-00-00-00",
3132
"mgt_encrypt_schm": {
@@ -214,8 +215,8 @@
214215
"fw_ver": "1.11.0 Build 230821 Rel.113553",
215216
"hw_id": "00000000000000000000000000000000",
216217
"hw_ver": "1.0",
217-
"jamming_rssi": -108,
218-
"jamming_signal_level": 2,
218+
"jamming_rssi": -119,
219+
"jamming_signal_level": 1,
219220
"lastOnboardingTimestamp": 1714016798,
220221
"mac": "202351000000",
221222
"model": "S200B",
@@ -224,7 +225,7 @@
224225
"parent_device_id": "0000000000000000000000000000000000000000",
225226
"region": "Europe/London",
226227
"report_interval": 16,
227-
"rssi": -66,
228+
"rssi": -60,
228229
"signal_level": 3,
229230
"specs": "EU",
230231
"status": "online",
@@ -245,8 +246,17 @@
245246
"getClockStatus": {
246247
"system": {
247248
"clock_status": {
248-
"local_time": "2024-11-01 13:56:27",
249-
"seconds_from_1970": 1730469387
249+
"local_time": "1984-10-21 23:48:23",
250+
"seconds_from_1970": 467246903
251+
}
252+
}
253+
},
254+
"getConnectStatus": {
255+
"onboarding": {
256+
"get_connect_status": {
257+
"current_ssid": "",
258+
"err_code": 0,
259+
"status": 0
250260
}
251261
}
252262
},
@@ -329,6 +339,10 @@
329339
}
330340
}
331341
},
342+
"getMatterSetupInfo": {
343+
"setup_code": "00000000000",
344+
"setup_payload": "00:000000-000000000000"
345+
},
332346
"getMediaEncrypt": {
333347
"cet": {
334348
"media_encrypt": {
@@ -353,7 +367,7 @@
353367
"getSirenConfig": {
354368
"duration": 300,
355369
"siren_type": "Doorbell Ring 1",
356-
"volume": "6"
370+
"volume": "1"
357371
},
358372
"getSirenStatus": {
359373
"status": "off",
@@ -389,5 +403,98 @@
389403
"zone_id": "Europe/London"
390404
}
391405
}
406+
},
407+
"scanApList": {
408+
"onboarding": {
409+
"scan": {
410+
"ap_list": [
411+
{
412+
"auth": 3,
413+
"bssid": "000000000000",
414+
"encryption": 2,
415+
"rssi": 2,
416+
"ssid": "I01BU0tFRF9TU0lEIw=="
417+
},
418+
{
419+
"auth": 3,
420+
"bssid": "000000000000",
421+
"encryption": 2,
422+
"rssi": 1,
423+
"ssid": "I01BU0tFRF9TU0lEIw=="
424+
},
425+
{
426+
"auth": 0,
427+
"bssid": "000000000000",
428+
"encryption": 0,
429+
"rssi": 2,
430+
"ssid": "I01BU0tFRF9TU0lEIw=="
431+
},
432+
{
433+
"auth": 3,
434+
"bssid": "000000000000",
435+
"encryption": 2,
436+
"rssi": 1,
437+
"ssid": "I01BU0tFRF9TU0lEIw=="
438+
},
439+
{
440+
"auth": 3,
441+
"bssid": "000000000000",
442+
"encryption": 2,
443+
"rssi": 1,
444+
"ssid": "I01BU0tFRF9TU0lEIw=="
445+
},
446+
{
447+
"auth": 3,
448+
"bssid": "000000000000",
449+
"encryption": 2,
450+
"rssi": 1,
451+
"ssid": "I01BU0tFRF9TU0lEIw=="
452+
},
453+
{
454+
"auth": 3,
455+
"bssid": "000000000000",
456+
"encryption": 2,
457+
"rssi": 3,
458+
"ssid": "I01BU0tFRF9TU0lEIw=="
459+
},
460+
{
461+
"auth": 3,
462+
"bssid": "000000000000",
463+
"encryption": 2,
464+
"rssi": 3,
465+
"ssid": "I01BU0tFRF9TU0lEIw=="
466+
},
467+
{
468+
"auth": 3,
469+
"bssid": "000000000000",
470+
"encryption": 2,
471+
"rssi": 1,
472+
"ssid": "I01BU0tFRF9TU0lEIw=="
473+
},
474+
{
475+
"auth": 4,
476+
"bssid": "000000000000",
477+
"encryption": 3,
478+
"rssi": 2,
479+
"ssid": "I01BU0tFRF9TU0lEIw=="
480+
},
481+
{
482+
"auth": 3,
483+
"bssid": "000000000000",
484+
"encryption": 2,
485+
"rssi": 1,
486+
"ssid": "I01BU0tFRF9TU0lEIw=="
487+
},
488+
{
489+
"auth": 3,
490+
"bssid": "000000000000",
491+
"encryption": 2,
492+
"rssi": 1,
493+
"ssid": "I01BU0tFRF9TU0lEIw=="
494+
}
495+
],
496+
"wpa3_supported": "false"
497+
}
498+
}
392499
}
393500
}

0 commit comments

Comments
 (0)
0