Add factory-reset command to cli (#1108)

Allow reseting devices to factory settings using the cli: `kasa device factory-reset`.
This commit is contained in:
Teemu R. 2024-09-21 16:52:52 +02:00 committed by GitHub
parent f07341a5a6
commit b7fa0d2040
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 0 deletions

View File

@ -166,6 +166,17 @@ async def reboot(plug, delay):
return await plug.reboot(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() @device.command()
@pass_dev @pass_dev
@click.option( @click.option(

View File

@ -19,6 +19,7 @@ from kasa import (
) )
from kasa.cli.device import ( from kasa.cli.device import (
alias, alias,
factory_reset,
led, led,
reboot, reboot,
state, state,
@ -215,6 +216,21 @@ async def test_reboot(dev, mocker, runner):
assert res.exit_code == 0 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 @device_smart
async def test_wifi_scan(dev, runner): async def test_wifi_scan(dev, runner):
res = await runner.invoke(wifi, ["scan"], obj=dev) res = await runner.invoke(wifi, ["scan"], obj=dev)