Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions custom_components/ocpp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,21 +795,21 @@ async def monitor_connection(self):
connection = self._connection
try:
while connection.open:
await asyncio.sleep(timeout)
time0 = time.perf_counter()
latency_ping = timeout * 1000
pong_waiter = await asyncio.wait_for(connection.ping(), timeout=timeout)
time1 = time.perf_counter()
latency_ping = round(time1 - time0, 3)
latency_ping = round(time1 - time0, 3) * 1000
latency_pong = timeout * 1000
await asyncio.wait_for(pong_waiter, timeout=timeout)
time2 = time.perf_counter()
latency_pong = round(time2 - time1, 3)
latency_pong = round(time2 - time1, 3) * 1000
_LOGGER.debug(
f"Connection latency from '{self.central.csid}' to '{self.id}': ping={latency_ping} ms, pong={latency_pong} ms",
)
self._metrics[cstat.latency_ping.value].value = latency_ping
self._metrics[cstat.latency_pong.value].value = latency_pong
await asyncio.sleep(timeout)

except asyncio.TimeoutError as timeout_exception:
self._metrics[cstat.latency_ping.value].value = latency_ping
Expand Down