From 693bc4f7ed38795099921254ccd121a20723add2 Mon Sep 17 00:00:00 2001 From: "Teemu R." Date: Wed, 4 Nov 2026 19:09:38 +0100 Subject: [PATCH] Use clearer error message for unsupported encryption types (#1831) Devices that announce an encryption type the library does not know, such as `TPAP` used by newer Tapo devices (e.g. RV20 Max Plus), previously failed with a generic message that dumped the whole encryption scheme: ``` Unsupported device 192.168.xx.xx of type SMART.TAPOROBOVAC with encrypt_scheme EncryptionScheme(is_support_https=True, encrypt_type='TPAP', http_port=4433, lv=2) ``` This can be rather confusing to interpret, as it does not tell what is not supported (e.g., the device type is definitely supported on non-tpap transports). This PR adds a separate check and error message for cases where the encryption type is not supported, giving this error: ``` Device 192.168.xx.xx (SMART.TAPOROBOVAC) uses unsupported encryption type TPAP ``` --- kasa/discover.py | 8 ++++++++ tests/test_discovery.py | 27 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/kasa/discover.py b/kasa/discover.py index fa95618c..b958e76f 100755 --- a/kasa/discover.py +++ b/kasa/discover.py @@ -845,6 +845,14 @@ class Discover: discovery_result=discovery_result.to_dict(), host=discovery_result.ip, ) + + if encrypt_type not in {e.value for e in DeviceEncryptionType}: + raise UnsupportedDeviceError( + f"Device {discovery_result.ip} ({type_}) uses unsupported " + f"encryption type {encrypt_type}", + discovery_result=discovery_result.to_dict(), + host=discovery_result.ip, + ) return DeviceConnectionParameters.from_values( type_, encrypt_type, diff --git a/tests/test_discovery.py b/tests/test_discovery.py index 7248c124..7f30a0a4 100644 --- a/tests/test_discovery.py +++ b/tests/test_discovery.py @@ -798,3 +798,30 @@ async def test_connection_parameters_from_encrypt_type_list_only(): result["encrypt_type"] = ["9"] with pytest.raises(UnsupportedDeviceError, match="no encryption type"): Discover._get_connection_parameters(DiscoveryResult.from_dict(result)) + + +async def test_connection_parameters_unsupported_encrypt_type(): + """An unknown encrypt_type is named in the error.""" + result = { + "device_type": "SMART.TAPOROBOVAC", + "device_model": "RV20 Max Plus(EU)", + "device_id": "0000000000000000000000000000000000000000", + "ip": "127.0.0.123", + "mac": "B0-19-21-00-00-00", + "mgt_encrypt_schm": { + "is_support_https": True, + "http_port": 4433, + "encrypt_type": "TPAP", + "lv": 2, + }, + } + with pytest.raises( + UnsupportedDeviceError, + match=( + r"^Device 127\.0\.0\.123 \(SMART\.TAPOROBOVAC\) uses unsupported " + r"encryption type TPAP$" + ), + ) as exc_info: + Discover._get_connection_parameters(DiscoveryResult.from_dict(result)) + assert exc_info.value.host == "127.0.0.123" + assert exc_info.value.discovery_result