From 1ce5af24948f51150b43c65d85afbce0dae11077 Mon Sep 17 00:00:00 2001 From: "Teemu R." Date: Fri, 27 Sep 2024 18:42:22 +0200 Subject: [PATCH] Add factory_reset() to iotdevice (#1125) Also extend the base device class API to make factory_reset() part of the common API. --- kasa/device.py | 7 +++++++ kasa/iot/iotdevice.py | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/kasa/device.py b/kasa/device.py index 2e0b3b2b..05a4f767 100644 --- a/kasa/device.py +++ b/kasa/device.py @@ -457,6 +457,13 @@ class Device(ABC): as the device reboots immediately without responding to the call. """ + @abstractmethod + async def factory_reset(self) -> None: + """Reset device back to factory settings. + + Note, this does not downgrade the firmware. + """ + def __repr__(self): if self._last_update is None: return f"<{self.device_type} at {self.host} - update() needed>" diff --git a/kasa/iot/iotdevice.py b/kasa/iot/iotdevice.py index 2dbc5e77..3986c001 100755 --- a/kasa/iot/iotdevice.py +++ b/kasa/iot/iotdevice.py @@ -561,6 +561,13 @@ class IotDevice(Device): """ await self._query_helper("system", "reboot", {"delay": delay}) + async def factory_reset(self) -> None: + """Reset device back to factory settings. + + Note, this does not downgrade the firmware. + """ + await self._query_helper("system", "reset") + async def turn_off(self, **kwargs) -> dict: """Turn off the device.""" raise NotImplementedError("Device subclass needs to implement this.")