Skip to content

Commit c9c8061

Browse files
authored
Fix camera login version in CLI (#1658)
Fix handling of --login-version/-lv for the CLI with --type "camera".
1 parent 932f3e2 commit c9c8061

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

kasa/cli/main.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,6 @@ async def cli(
312312
if type == "camera":
313313
encrypt_type = "AES"
314314
https = True
315-
login_version = 2
316315
device_family = "SMART.IPCAMERA"
317316

318317
from kasa.device import Device

tests/test_cli.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,43 @@ async def _state(dev: Device):
10391039
assert isinstance(result_device, expected_type)
10401040

10411041

1042+
@pytest.mark.parametrize(
1043+
("cli_login_version", "expected_login_version"),
1044+
[
1045+
pytest.param(None, 2, id="No login-version defaults to 2"),
1046+
pytest.param(3, 3, id="Explicit login-version 3 is preserved"),
1047+
pytest.param(2, 2, id="Explicit login-version 2 is preserved"),
1048+
],
1049+
)
1050+
async def test_type_camera_login_version(
1051+
cli_login_version, expected_login_version, mocker, runner
1052+
):
1053+
"""Test that --type camera respects an explicitly provided --login-version."""
1054+
from kasa.deviceconfig import DeviceConfig
1055+
1056+
captured_config: DeviceConfig | None = None
1057+
1058+
mocker.patch("kasa.cli.device.state")
1059+
1060+
async def _mock_connect(config: DeviceConfig):
1061+
nonlocal captured_config
1062+
captured_config = config
1063+
dev = SmartCamDevice(host="127.0.0.1", config=config)
1064+
return dev
1065+
1066+
mocker.patch("kasa.device.Device.connect", side_effect=_mock_connect)
1067+
mocker.patch.object(SmartCamDevice, "update")
1068+
1069+
args = ["--type", "camera", "--host", "127.0.0.1"]
1070+
if cli_login_version is not None:
1071+
args += ["--login-version", str(cli_login_version)]
1072+
1073+
res = await runner.invoke(cli, args)
1074+
assert res.exit_code == 0, res.output
1075+
assert captured_config is not None
1076+
assert captured_config.connection_type.login_version == expected_login_version
1077+
1078+
10421079
@pytest.mark.skip(
10431080
"Skip until pytest-asyncio supports pytest 8.0, https://github.com/pytest-dev/pytest-asyncio/issues/737"
10441081
)

0 commit comments

Comments
 (0)