@@ -79,8 +79,9 @@ def _update_time_sync(self) -> None:
79
79
is received within socket_timeout seconds, ArithmeticError for substantially incorrect
80
80
NTP results."""
81
81
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
+ ]
84
85
85
86
self ._packet [0 ] = 0b00100011 # Not leap second, NTP version 4, Client mode
86
87
for i in range (1 , PACKET_SIZE ):
@@ -103,14 +104,18 @@ def _update_time_sync(self) -> None:
103
104
srv_send_s , srv_send_f = struct .unpack_from ("!II" , self ._packet , offset = 40 )
104
105
105
106
# 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
+ )
110
113
111
114
# _round_trip_delay = (local_recv_ns - local_send_ns) - (srv_send_ns - srv_recv_ns)
112
115
# 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
114
119
115
120
self ._monotonic_start_ns = clock_offset + self ._tz_offset * 1_000_000_000
116
121
@@ -122,7 +127,9 @@ def datetime(self) -> time.struct_time:
122
127
self ._update_time_sync ()
123
128
124
129
# 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
126
133
127
134
return time .localtime (current_time_s )
128
135
0 commit comments