mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-06 18:54:08 +00:00
Add time sync command (#951)
Allows setting the device time (on SMART devices) to the current time. Fixes also setting the time which was previously broken.
This commit is contained in:
@@ -51,7 +51,13 @@ class Time(SmartModule):
|
||||
async def set_time(self, dt: datetime):
|
||||
"""Set device time."""
|
||||
unixtime = mktime(dt.timetuple())
|
||||
offset = cast(timedelta, dt.utcoffset())
|
||||
diff = offset / timedelta(minutes=1)
|
||||
return await self.call(
|
||||
"set_device_time",
|
||||
{"timestamp": unixtime, "time_diff": dt.utcoffset(), "region": dt.tzname()},
|
||||
{
|
||||
"timestamp": int(unixtime),
|
||||
"time_diff": int(diff),
|
||||
"region": dt.tzname(),
|
||||
},
|
||||
)
|
||||
|
Reference in New Issue
Block a user