@@ -79,8 +79,9 @@ def _update_time_sync(self) -> None:
7979 is received within socket_timeout seconds, ArithmeticError for substantially incorrect
8080 NTP results."""
8181 if self ._socket_address is None :
82- self ._socket_address = self ._pool .getaddrinfo (
83- self ._server , self ._port )[0 ][4 ]
82+ self ._socket_address = self ._pool .getaddrinfo (self ._server , self ._port )[0 ][
83+ 4
84+ ]
8485
8586 self ._packet [0 ] = 0b00100011 # Not leap second, NTP version 4, Client mode
8687 for i in range (1 , PACKET_SIZE ):
@@ -103,14 +104,18 @@ def _update_time_sync(self) -> None:
103104 srv_send_s , srv_send_f = struct .unpack_from ("!II" , self ._packet , offset = 40 )
104105
105106 # Convert the server times from NTP to UTC for local use
106- srv_recv_ns = (srv_recv_s - NTP_TO_UNIX_EPOCH ) * 1_000_000_000 + \
107- (srv_recv_f * 1_000_000_000 // 2 ** 32 )
108- srv_send_ns = (srv_send_s - NTP_TO_UNIX_EPOCH ) * 1_000_000_000 + \
109- (srv_send_f * 1_000_000_000 // 2 ** 32 )
107+ srv_recv_ns = (srv_recv_s - NTP_TO_UNIX_EPOCH ) * 1_000_000_000 + (
108+ srv_recv_f * 1_000_000_000 // 2 ** 32
109+ )
110+ srv_send_ns = (srv_send_s - NTP_TO_UNIX_EPOCH ) * 1_000_000_000 + (
111+ srv_send_f * 1_000_000_000 // 2 ** 32
112+ )
110113
111114 # _round_trip_delay = (local_recv_ns - local_send_ns) - (srv_send_ns - srv_recv_ns)
112115 # Calculate (best estimate) offset between server UTC and board monotonic_ns time
113- clock_offset = ((srv_recv_ns - local_send_ns ) + (srv_send_ns - local_recv_ns )) // 2
116+ clock_offset = (
117+ (srv_recv_ns - local_send_ns ) + (srv_send_ns - local_recv_ns )
118+ ) // 2
114119
115120 self ._monotonic_start_ns = clock_offset + self ._tz_offset * 1_000_000_000
116121
@@ -122,7 +127,9 @@ def datetime(self) -> time.struct_time:
122127 self ._update_time_sync ()
123128
124129 # Calculate the current time based on the current and start monotonic times
125- current_time_s = (time .monotonic_ns () + self ._monotonic_start_ns ) // 1_000_000_000
130+ current_time_s = (
131+ time .monotonic_ns () + self ._monotonic_start_ns
132+ ) // 1_000_000_000
126133
127134 return time .localtime (current_time_s )
128135
0 commit comments