Skip to content

Commit fce5d6b

Browse files
committed
Get proper datetime to compare the received datetime with
1 parent fb78cfc commit fce5d6b

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

plugwise_usb/nodes/circle_plus.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ async def load(self) -> bool:
6767

6868
async def clock_synchronize(self) -> bool:
6969
"""Synchronize realtime clock. Returns true if successful."""
70+
_dt_req_to_circle: datetime = datetime.now(tz=UTC)
7071
clock_request = CirclePlusRealTimeClockGetRequest(
7172
self._send, self._mac_in_bytes
7273
)
@@ -78,16 +79,16 @@ async def clock_synchronize(self) -> bool:
7879
return False
7980
await self._available_update_state(True, clock_response.timestamp)
8081

81-
_dt_of_circle: datetime = datetime.now(tz=UTC).replace(
82-
hour=clock_response.time.value.hour,
83-
minute=clock_response.time.value.minute,
84-
second=clock_response.time.value.second,
85-
microsecond=0,
86-
tzinfo=UTC,
87-
)
88-
_LOGGER.debug("HOI circle+ clock=%s", clock_response.timestamp.replace(microsecond=0))
89-
_LOGGER.debug("HOI _dt_of_circle=%s", _dt_of_circle)
90-
clock_offset = clock_response.timestamp.replace(microsecond=0) - _dt_of_circle
82+
# _dt_req_to_circle: datetime = datetime.now(tz=UTC).replace(
83+
# hour=clock_response.time.value.hour,
84+
# minute=clock_response.time.value.minute,
85+
# second=clock_response.time.value.second,
86+
# microsecond=0,
87+
# tzinfo=UTC,
88+
# )
89+
_LOGGER.debug("HOI circle+ clock=%s", clock_response.timestamp)
90+
_LOGGER.debug("HOI _dt_req_to_circle=%s", _dt_req_to_circle)
91+
clock_offset = clock_response.timestamp.replace(microsecond=0) - _dt_req_to_circle
9192
if abs(clock_offset.total_seconds()) < MAX_TIME_DRIFT:
9293
return True
9394
_LOGGER.info(

0 commit comments

Comments
 (0)