Skip to content

Commit db329b6

Browse files
committed
FIx types in UptimeKumaMonitor and add status enum
1 parent 41503af commit db329b6

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

pythonkuma/models.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,23 @@
22

33
from __future__ import annotations
44

5-
from dataclasses import dataclass
6-
from enum import StrEnum
5+
from dataclasses import dataclass, field
6+
from enum import IntEnum, StrEnum
77
from typing import Any
88

9+
from mashumaro import DataClassDictMixin
910
from prometheus_client.parser import text_string_to_metric_families as parser
1011

1112

13+
class MonitorStatus(IntEnum):
14+
"""Monitor states."""
15+
16+
DOWN = 0
17+
UP = 1
18+
PENDING = 2
19+
MAINTENANCE = 3
20+
21+
1222
class MonitorType(StrEnum):
1323
"""Monitors type."""
1424

@@ -36,33 +46,24 @@ class MonitorType(StrEnum):
3646
TAILSCALE_PING = "tailscale-ping"
3747

3848

39-
class UptimeKumaBaseModel:
49+
@dataclass
50+
class UptimeKumaBaseModel(DataClassDictMixin):
4051
"""UptimeKumaBaseModel."""
4152

4253

43-
@dataclass
54+
@dataclass(kw_only=True)
4455
class UptimeKumaMonitor(UptimeKumaBaseModel):
4556
"""Monitor model for Uptime Kuma."""
4657

47-
monitor_cert_days_remaining: float = 0
48-
monitor_cert_is_valid: float = 0
49-
monitor_hostname: str = ""
58+
monitor_cert_days_remaining: int
59+
monitor_cert_is_valid: bool
60+
monitor_hostname: str | None = field(metadata={"deserialize": lambda v: None if v == "null" else v})
5061
monitor_name: str = ""
51-
monitor_port: str = ""
52-
monitor_response_time: float = 0
53-
monitor_status: float = 0
62+
monitor_port: str | None = field(metadata={"deserialize": lambda v: None if v == "null" else v})
63+
monitor_response_time: int = 0
64+
monitor_status: MonitorStatus
5465
monitor_type: MonitorType = MonitorType.HTTP
55-
monitor_url: str = ""
56-
57-
@staticmethod
58-
def from_dict(data: dict[str, Any]) -> UptimeKumaMonitor:
59-
"""Generate object from json."""
60-
obj: dict[str, Any] = {}
61-
for key, value in data.items():
62-
if hasattr(UptimeKumaMonitor, key):
63-
obj[key] = MonitorType(value) if key == "monitor_type" else value
64-
65-
return UptimeKumaMonitor(**obj)
66+
monitor_url: str | None = field(metadata={"deserialize": lambda v: None if v == "null" else v})
6667

6768

6869
@dataclass

0 commit comments

Comments
 (0)