do not wait for events that are not sent
This commit is contained in:
parent
01664f5fbc
commit
ed4a6130fe
2 changed files with 19 additions and 0 deletions
|
@ -378,6 +378,7 @@ class UptimeKumaApi(object):
|
|||
"uptime": None,
|
||||
"heartbeat": None,
|
||||
"info": None,
|
||||
"certInfo": None
|
||||
}
|
||||
|
||||
self.sio.on("connect", self._event_connect)
|
||||
|
@ -392,11 +393,16 @@ class UptimeKumaApi(object):
|
|||
self.sio.on("uptime", self._event_uptime)
|
||||
self.sio.on("heartbeat", self._event_heartbeat)
|
||||
self.sio.on("info", self._event_info)
|
||||
self.sio.on("certInfo", self._event_cert_info)
|
||||
|
||||
self.connect(url)
|
||||
|
||||
def _get_event_data(self, event):
|
||||
monitor_events = ["avgPing", "uptime", "heartbeatList", "importantHeartbeatList", "certInfo", "heartbeat"]
|
||||
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) # wait for multiple messages
|
||||
return self._event_data[event]
|
||||
|
@ -472,6 +478,14 @@ class UptimeKumaApi(object):
|
|||
def _event_info(self, 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
|
||||
|
||||
def connect(self, url: str):
|
||||
|
@ -685,6 +699,11 @@ class UptimeKumaApi(object):
|
|||
def avg_ping(self):
|
||||
return self._get_event_data("avgPing")
|
||||
|
||||
# cert info
|
||||
|
||||
def cert_info(self):
|
||||
return self._get_event_data("certInfo")
|
||||
|
||||
# uptime
|
||||
|
||||
def uptime(self):
|
||||
|
|
0
uptime_kuma_api/events.py
Normal file
0
uptime_kuma_api/events.py
Normal file
Loading…
Reference in a new issue