Skip to content

Commit 3770ed3

Browse files
committed
CirclePlus: handle time-diff larger than 24hrs
1 parent f301c5b commit 3770ed3

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

plugwise_usb/nodes/circle_plus.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,19 @@ async def clock_synchronize(self) -> bool:
7878
return False
7979
await self._available_update_state(True, response.timestamp)
8080

81-
circle_plus_dt: datetime = datetime.now(tz=UTC).replace(
82-
hour=response.time.value.hour,
81+
dt_now = datetime.now(tz=UTC)
82+
days_diff = response.day_of_week - dt_now.weekday()
83+
circle_plus_ts: datetime = dt_now.replace(
84+
hour=response.time.value.hour + (24 * days_diff),
8385
minute=response.time.value.minute,
8486
second=response.time.value.second,
8587
microsecond=0,
8688
tzinfo=UTC,
8789
)
88-
_LOGGER.debug("HOI circle+ clock=%s", circle_plus_dt)
90+
_LOGGER.debug("HOI circle+ clock=%s", circle_plus_ts)
8991
_LOGGER.debug("HOI response timestamp=%s", response.timestamp)
9092
clock_offset = (
91-
response.timestamp.replace(microsecond=0) - circle_plus_dt
93+
response.timestamp.replace(microsecond=0) - circle_plus_ts
9294
)
9395
if abs(clock_offset.total_seconds()) < MAX_TIME_DRIFT:
9496
return True

0 commit comments

Comments
 (0)