From ce1cc1274052d5ac08621199830634153197fb71 Mon Sep 17 00:00:00 2001 From: lucasheld Date: Sat, 20 May 2023 20:35:04 +0200 Subject: [PATCH] fix: adjust `get_monitor_status` method to previous changes --- tests/test_helper_methods.py | 15 +++++++++++++++ uptime_kuma_api/api.py | 19 ++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 tests/test_helper_methods.py diff --git a/tests/test_helper_methods.py b/tests/test_helper_methods.py new file mode 100644 index 0000000..598c88a --- /dev/null +++ b/tests/test_helper_methods.py @@ -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() diff --git a/uptime_kuma_api/api.py b/uptime_kuma_api/api.py index d003950..0c761cf 100644 --- a/uptime_kuma_api/api.py +++ b/uptime_kuma_api/api.py @@ -3677,9 +3677,22 @@ class UptimeKumaApi(object): # helper methods 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) + + """ heartbeats = self.get_heartbeats() - for heartbeat in heartbeats: - if int(heartbeat["id"]) == monitor_id: - status = heartbeat["data"][-1]["status"] + for heartbeat_monitor_id in heartbeats: + if heartbeat_monitor_id == monitor_id: + status = heartbeats[heartbeat_monitor_id][-1]["status"] return MonitorStatus(status) raise UptimeKumaException("monitor does not exist")