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:
Teemu R
2024-06-17 10:37:08 +02:00
committed by GitHub
parent 6cdbbefb90
commit 867b7b8830
4 changed files with 75 additions and 3 deletions

View File

@@ -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(),
},
)