Fix camera login version in CLI (#1658)
Some checks failed
CI / Perform Lint Checks (3.13) (push) Has been cancelled
CodeQL Checks / Analyze (python) (push) Has been cancelled
CI / Python 3.11 on macos-latest (push) Has been cancelled
CI / Python 3.12 on macos-latest (push) Has been cancelled
CI / Python 3.13 on macos-latest (push) Has been cancelled
CI / Python 3.11 on ubuntu-latest (push) Has been cancelled
CI / Python 3.12 on ubuntu-latest (push) Has been cancelled
CI / Python 3.13 on ubuntu-latest (push) Has been cancelled
CI / Python 3.11 on windows-latest (push) Has been cancelled
CI / Python 3.12 on windows-latest (push) Has been cancelled
CI / Python 3.13 on windows-latest (push) Has been cancelled
Stale / stale (push) Has been cancelled

Fix handling of --login-version/-lv for the CLI with --type "camera".
This commit is contained in:
ZeliardM
2026-02-26 18:46:11 -05:00
committed by GitHub
parent 932f3e21e0
commit c9c80619d7
2 changed files with 37 additions and 1 deletions

View File

@@ -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

View File

@@ -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"
)