From c9c80619d76e21bd1458f10084c6d2ef2daae8f1 Mon Sep 17 00:00:00 2001 From: ZeliardM <140266236+ZeliardM@users.noreply.github.com> Date: Thu, 26 Feb 2026 18:46:11 -0500 Subject: [PATCH] Fix camera login version in CLI (#1658) Fix handling of --login-version/-lv for the CLI with --type "camera". --- kasa/cli/main.py | 1 - tests/test_cli.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/kasa/cli/main.py b/kasa/cli/main.py index 4f1eccda..15ad211b 100755 --- a/kasa/cli/main.py +++ b/kasa/cli/main.py @@ -312,7 +312,6 @@ async def cli( if type == "camera": encrypt_type = "AES" https = True - login_version = 2 device_family = "SMART.IPCAMERA" from kasa.device import Device diff --git a/tests/test_cli.py b/tests/test_cli.py index c5c06b7b..6cba5d2a 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1039,6 +1039,43 @@ async def test_type_param(device_type, mocker, runner): assert isinstance(result_device, expected_type) +@pytest.mark.parametrize( + ("cli_login_version", "expected_login_version"), + [ + pytest.param(None, 2, id="No login-version defaults to 2"), + pytest.param(3, 3, id="Explicit login-version 3 is preserved"), + pytest.param(2, 2, id="Explicit login-version 2 is preserved"), + ], +) +async def test_type_camera_login_version( + cli_login_version, expected_login_version, mocker, runner +): + """Test that --type camera respects an explicitly provided --login-version.""" + from kasa.deviceconfig import DeviceConfig + + captured_config: DeviceConfig | None = None + + mocker.patch("kasa.cli.device.state") + + async def _mock_connect(config: DeviceConfig): + nonlocal captured_config + captured_config = config + dev = SmartCamDevice(host="127.0.0.1", config=config) + return dev + + mocker.patch("kasa.device.Device.connect", side_effect=_mock_connect) + mocker.patch.object(SmartCamDevice, "update") + + args = ["--type", "camera", "--host", "127.0.0.1"] + if cli_login_version is not None: + args += ["--login-version", str(cli_login_version)] + + res = await runner.invoke(cli, args) + assert res.exit_code == 0, res.output + assert captured_config is not None + assert captured_config.connection_type.login_version == expected_login_version + + @pytest.mark.skip( "Skip until pytest-asyncio supports pytest 8.0, https://github.com/pytest-dev/pytest-asyncio/issues/737" )