Skip to content

Commit eba5cb6

Browse files
committed
fix clock offset detection. Original code did not properly check for
negative offsets.
1 parent 296b0a0 commit eba5cb6

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

plugwise_usb/nodes/circle.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -864,9 +864,9 @@ async def _clock_synchronize_scheduler(self) -> None:
864864
try:
865865
await self.clock_synchronize()
866866
except Exception:
867-
_LOGGER.exception("Clock synchronisation failed for %s", self.name)
867+
_LOGGER.exception("Clock synchronisation failed for %s", self.mac_in_str)
868868
except CancelledError:
869-
_LOGGER.debug("Clock sync scheduler cancelled for %s", self.name)
869+
_LOGGER.debug("Clock sync scheduler cancelled for %s", self.mac_in_str)
870870
raise
871871

872872
async def clock_synchronize(self) -> bool:
@@ -883,9 +883,7 @@ async def clock_synchronize(self) -> bool:
883883
tzinfo=UTC,
884884
)
885885
clock_offset = clock_response.timestamp.replace(microsecond=0) - _dt_of_circle
886-
if (clock_offset.seconds < MAX_TIME_DRIFT) or (
887-
clock_offset.seconds > -(MAX_TIME_DRIFT)
888-
):
886+
if abs(clock_offset.total_seconds()) < MAX_TIME_DRIFT:
889887
return True
890888
_LOGGER.info(
891889
"Reset clock of node %s because time has drifted %s sec",

plugwise_usb/nodes/circle_plus.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,7 @@ async def clock_synchronize(self) -> bool:
8686
tzinfo=UTC,
8787
)
8888
clock_offset = clock_response.timestamp.replace(microsecond=0) - _dt_of_circle
89-
if (clock_offset.seconds < MAX_TIME_DRIFT) or (
90-
clock_offset.seconds > -(MAX_TIME_DRIFT)
91-
):
89+
if abs(clock_offset.total_seconds()) < MAX_TIME_DRIFT:
9290
return True
9391
_LOGGER.info(
9492
"Reset realtime clock of node %s because time has drifted %s seconds while max drift is set to %s seconds)",

0 commit comments

Comments
 (0)