Add reboot and factory_reset to tapodevice (#686)

* Add reboot and factory_reset to tapodevice

* Add test for reboot command

* Fix mocking as different protocols use different methods for comms..
This commit is contained in:
Teemu R 2024-01-23 14:26:47 +01:00 committed by GitHub
parent cfbdf7c64a
commit c8ac3a29c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 0 deletions

View File

@ -339,3 +339,18 @@ class TapoDevice(SmartDevice):
"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")

View File

@ -21,6 +21,7 @@ from kasa.cli import (
cli,
emeter,
raw_command,
reboot,
state,
sysinfo,
toggle,
@ -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()