fix: adjust get_monitor_status method to previous changes

This commit is contained in:
lucasheld 2023-05-20 20:35:04 +02:00
parent 762dd4a657
commit ce1cc12740
2 changed files with 31 additions and 3 deletions

View file

@ -0,0 +1,15 @@
import unittest
from uptime_kuma_api import MonitorStatus
from uptime_kuma_test_case import UptimeKumaTestCase
class TestHelperMethods(UptimeKumaTestCase):
def test_monitor_status(self):
monitor_id = self.add_monitor()
status = self.api.get_monitor_status(monitor_id)
self.assertTrue(type(status) == MonitorStatus)
if __name__ == '__main__':
unittest.main()

View file

@ -3677,9 +3677,22 @@ class UptimeKumaApi(object):
# helper methods # helper methods
def get_monitor_status(self, monitor_id: int) -> MonitorStatus: def get_monitor_status(self, monitor_id: int) -> MonitorStatus:
"""
Get the monitor status.
:param int monitor_id: Id of the monitor.
:return: The monitor status.
:rtype: MonitorStatus
:raises UptimeKumaException: If the monitor does not exist.
Example::
>>> api.get_monitor_status(1)
<MonitorStatus.PENDING: 2>
"""
heartbeats = self.get_heartbeats() heartbeats = self.get_heartbeats()
for heartbeat in heartbeats: for heartbeat_monitor_id in heartbeats:
if int(heartbeat["id"]) == monitor_id: if heartbeat_monitor_id == monitor_id:
status = heartbeat["data"][-1]["status"] status = heartbeats[heartbeat_monitor_id][-1]["status"]
return MonitorStatus(status) return MonitorStatus(status)
raise UptimeKumaException("monitor does not exist") raise UptimeKumaException("monitor does not exist")