Skip to content

Add reboot and factory_reset to tapodevice #686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 23, 2024
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
15 changes: 15 additions & 0 deletions kasa/tapo/tapodevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,3 +339,18 @@ async def update_credentials(self, username: str, password: str):
"time": t,
}
return await self.protocol.query({"set_qs_info": payload})

async def reboot(self, delay: int = 1) -> None:
"""Reboot the device.

Note that giving a delay of zero causes this to block,
as the device reboots immediately without responding to the call.
"""
await self.protocol.query({"device_reboot": {"delay": delay}})

async def factory_reset(self) -> None:
"""Reset device back to factory settings.

Note, this does not downgrade the firmware.
"""
await self.protocol.query("device_reset")
16 changes: 16 additions & 0 deletions kasa/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
cli,
emeter,
raw_command,
reboot,
state,
sysinfo,
toggle,
Expand Down Expand Up @@ -103,6 +104,21 @@ async def test_raw_command(dev):
assert "Usage" in res.output


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

res = await runner.invoke(
reboot,
obj=dev,
)

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


@device_smart
async def test_wifi_scan(dev):
runner = CliRunner()
Expand Down