Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions kasa/cli/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,17 @@ async def reboot(plug, delay):
return await plug.reboot(delay)


@device.command()
@pass_dev
async def factory_reset(plug):
"""Reset device to factory settings."""
click.confirm(
"Do you really want to reset the device to factory settings?", abort=True
)

return await plug.factory_reset()


@device.command()
@pass_dev
@click.option(
Expand Down
16 changes: 16 additions & 0 deletions kasa/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
)
from kasa.cli.device import (
alias,
factory_reset,
led,
reboot,
state,
Expand Down Expand Up @@ -215,6 +216,21 @@ async def test_reboot(dev, mocker, runner):
assert res.exit_code == 0


@device_smart
async def test_factory_reset(dev, mocker, runner):
"""Test that factory reset works on SMART devices."""
query_mock = mocker.patch.object(dev.protocol, "query")

res = await runner.invoke(
factory_reset,
obj=dev,
input="y\n",
)

query_mock.assert_called()
assert res.exit_code == 0


@device_smart
async def test_wifi_scan(dev, runner):
res = await runner.invoke(wifi, ["scan"], obj=dev)
Expand Down