#2042: extract code into request_time() method.

This commit is contained in:
Nick Todd
2023-11-22 14:40:44 +00:00
parent 3f76e09521
commit 006a37d268

View File

@@ -93,10 +93,19 @@ class NTPClient(Service):
_LOGGER.debug(f"{payload} is not a NTPPacket") _LOGGER.debug(f"{payload} is not a NTPPacket")
return False return False
if payload.ntp_reply.ntp_datetime: if payload.ntp_reply.ntp_datetime:
self.sys_log.info(f"{self.name}: Received time update from NTP server{payload.ntp_reply.ntp_datetime}") self.sys_log.info(
f"{self.name}: \
Received time update from NTP server{payload.ntp_reply.ntp_datetime}"
)
self.time = payload.ntp_reply.ntp_datetime self.time = payload.ntp_reply.ntp_datetime
return True return True
def request_time(self) -> None:
"""Send request to ntp_server."""
ntp_request = NTPRequest(ntp_client=self.ip_addr)
ntp_server_packet = NTPPacket(ntp_request=ntp_request)
self.send(payload=ntp_server_packet)
def apply_timestep(self, timestep: int) -> None: def apply_timestep(self, timestep: int) -> None:
""" """
For each timestep request the time from the NTP server. For each timestep request the time from the NTP server.
@@ -112,8 +121,6 @@ class NTPClient(Service):
super().apply_timestep(timestep) super().apply_timestep(timestep)
if self.operating_state == ServiceOperatingState.RUNNING: if self.operating_state == ServiceOperatingState.RUNNING:
# request time from server # request time from server
ntp_request = NTPRequest(ntp_client=self.ip_addr) self.request_time()
ntp_server_packet = NTPPacket(ntp_request=ntp_request)
self.send(payload=ntp_server_packet)
else: else:
self.sys_log.debug(f"{self.name} ntp client not running") self.sys_log.debug(f"{self.name} ntp client not running")