do not wait for events that are not sent

This commit is contained in:
lucasheld 2022-08-05 15:48:02 +02:00
parent 01664f5fbc
commit ed4a6130fe
2 changed files with 19 additions and 0 deletions

View file

@ -378,6 +378,7 @@ class UptimeKumaApi(object):
"uptime": None, "uptime": None,
"heartbeat": None, "heartbeat": None,
"info": None, "info": None,
"certInfo": None
} }
self.sio.on("connect", self._event_connect) self.sio.on("connect", self._event_connect)
@ -392,11 +393,16 @@ class UptimeKumaApi(object):
self.sio.on("uptime", self._event_uptime) self.sio.on("uptime", self._event_uptime)
self.sio.on("heartbeat", self._event_heartbeat) self.sio.on("heartbeat", self._event_heartbeat)
self.sio.on("info", self._event_info) self.sio.on("info", self._event_info)
self.sio.on("certInfo", self._event_cert_info)
self.connect(url) self.connect(url)
def _get_event_data(self, event): def _get_event_data(self, event):
monitor_events = ["avgPing", "uptime", "heartbeatList", "importantHeartbeatList", "certInfo", "heartbeat"]
while self._event_data[event] is None: while self._event_data[event] is None:
# do not wait for events that are not sent
if self._event_data["monitorList"] == {} and event in monitor_events:
return []
time.sleep(0.01) time.sleep(0.01)
time.sleep(0.01) # wait for multiple messages time.sleep(0.01) # wait for multiple messages
return self._event_data[event] return self._event_data[event]
@ -472,6 +478,14 @@ class UptimeKumaApi(object):
def _event_info(self, data): def _event_info(self, data):
self._event_data["info"] = data self._event_data["info"] = data
def _event_cert_info(self, id_, data):
if self._event_data["certInfo"] is None:
self._event_data["certInfo"] = []
self._event_data["certInfo"].append({
"id": id_,
"data": data,
})
# connection # connection
def connect(self, url: str): def connect(self, url: str):
@ -685,6 +699,11 @@ class UptimeKumaApi(object):
def avg_ping(self): def avg_ping(self):
return self._get_event_data("avgPing") return self._get_event_data("avgPing")
# cert info
def cert_info(self):
return self._get_event_data("certInfo")
# uptime # uptime
def uptime(self): def uptime(self):

View file