From 998ebe79e825d4e1f25013037b7b33fd0569bf6b Mon Sep 17 00:00:00 2001 From: Brian Marks Date: Wed, 30 Sep 2026 13:33:30 -0400 Subject: [PATCH] fix: use KLAP v2 transport for IOT devices with login version 2 (#1731) Some IOT-family devices keep the legacy IOT command set after a firmware update but upgrade their KLAP authentication to login version 2 (sha256 hashing). This change selects `KlapTransportV2` for `IOT.KLAP` devices that advertise `login_version >= 2`, matching the transport already used for `SMART.KLAP`. Devices with login version 1 (or unset) are unchanged and continue to use the v1 `KlapTransport`. Co-authored-by: Claude Opus 4.8 --- kasa/device_factory.py | 6 ++++++ tests/test_device_factory.py | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/kasa/device_factory.py b/kasa/device_factory.py index ecb0d0a1..8f7c2571 100644 --- a/kasa/device_factory.py +++ b/kasa/device_factory.py @@ -239,4 +239,10 @@ def get_protocol(config: DeviceConfig, *, strict: bool = False) -> BaseProtocol if not (prot_tran_cls := supported_device_protocols.get(protocol_transport_key)): return None protocol_cls, transport_cls = prot_tran_cls + if ( + protocol_transport_key == "IOT.KLAP" + and ctype.login_version + and ctype.login_version >= 2 + ): + transport_cls = KlapTransportV2 return protocol_cls(transport=transport_cls(config=config)) diff --git a/tests/test_device_factory.py b/tests/test_device_factory.py index 19ccfb73..0f4b31e3 100644 --- a/tests/test_device_factory.py +++ b/tests/test_device_factory.py @@ -259,6 +259,18 @@ ET = DeviceEncryptionType KlapTransport, id="iot-klap", ), + pytest.param( + CP(DF.IotSmartPlugSwitch, ET.Klap, login_version=1, https=False), + IotProtocol, + KlapTransport, + id="iot-klap-v1", + ), + pytest.param( + CP(DF.IotSmartPlugSwitch, ET.Klap, login_version=2, https=False), + IotProtocol, + KlapTransportV2, + id="iot-klap-v2", + ), pytest.param( CP(DF.IotSmartPlugSwitch, ET.Xor, https=False), IotProtocol,