47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
|
|
from dataclasses import dataclass, field
|
||
|
|
|
||
|
|
|
||
|
|
@dataclass
|
||
|
|
class BlueBubblesStatus:
|
||
|
|
account_id: str
|
||
|
|
connected: bool = False
|
||
|
|
server_url: str = ""
|
||
|
|
private_api_enabled: bool = False
|
||
|
|
imessage_logged_in: bool = False
|
||
|
|
os_version: str | None = None
|
||
|
|
macos_major: int | None = None
|
||
|
|
ws_connected: bool = False
|
||
|
|
webhook_configured: bool = False
|
||
|
|
issues: list[str] = field(default_factory=list)
|
||
|
|
|
||
|
|
@property
|
||
|
|
def is_healthy(self) -> bool:
|
||
|
|
return self.connected and self.imessage_logged_in and not self.issues
|
||
|
|
|
||
|
|
@property
|
||
|
|
def status_text(self) -> str:
|
||
|
|
if not self.connected:
|
||
|
|
return "disconnected"
|
||
|
|
if not self.imessage_logged_in:
|
||
|
|
return "iMessage not logged in"
|
||
|
|
if not self.private_api_enabled:
|
||
|
|
return "public-api-only"
|
||
|
|
return "healthy"
|
||
|
|
|
||
|
|
|
||
|
|
def build_status_report(status: BlueBubblesStatus) -> dict:
|
||
|
|
return {
|
||
|
|
"account_id": status.account_id,
|
||
|
|
"connected": status.connected,
|
||
|
|
"server_url": status.server_url,
|
||
|
|
"private_api_enabled": status.private_api_enabled,
|
||
|
|
"imessage_logged_in": status.imessage_logged_in,
|
||
|
|
"os_version": status.os_version,
|
||
|
|
"macos_major": status.macos_major,
|
||
|
|
"ws_connected": status.ws_connected,
|
||
|
|
"webhook_configured": status.webhook_configured,
|
||
|
|
"is_healthy": status.is_healthy,
|
||
|
|
"status_text": status.status_text,
|
||
|
|
"issues": status.issues,
|
||
|
|
}
|