Backup automatico script del 2026-08-23 12:04
This commit is contained in:
1 parent
11823447a2
commit
795a15a7b6
66 files changed
+8546
No files matched your search
@@ -0,0 +1,75 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Client Loogle Casa — dashboard, meteo, rete."""
|
||||
|
||||
import os
|
||||
from typing import Any, Optional
|
||||
|
||||
from .session_client import SessionApiClient
|
||||
|
||||
MCP_USERS = ("daniele", "lucia", "davide", "luca")
|
||||
# Daniele MCP → admin su Loogle Casa
|
||||
MCP_TO_SERVICE_USER = {
|
||||
"daniele": "admin",
|
||||
"lucia": "lucia",
|
||||
"davide": "davide",
|
||||
"luca": "luca",
|
||||
}
|
||||
|
||||
|
||||
def _service_username(mcp_username: str) -> str:
|
||||
return MCP_TO_SERVICE_USER.get(mcp_username.lower(), mcp_username.lower())
|
||||
PUBLIC_URL = os.environ.get("LOOGLE_CASA_URL", "https://casa.loogle.it").rstrip("/")
|
||||
API_URL = os.environ.get("LOOGLE_CASA_API_URL", PUBLIC_URL).rstrip("/")
|
||||
|
||||
_client: Optional[SessionApiClient] = None
|
||||
|
||||
|
||||
def _client_instance() -> SessionApiClient:
|
||||
global _client
|
||||
if _client is None:
|
||||
verify = os.environ.get("LOOGLE_CASA_VERIFY_SSL", "true").strip().lower() not in (
|
||||
"0", "false", "no", "off",
|
||||
)
|
||||
client = SessionApiClient(
|
||||
service="LOOGLE_CASA",
|
||||
base_url=API_URL,
|
||||
verify_ssl=verify,
|
||||
)
|
||||
client.map_username = _service_username # type: ignore[attr-defined]
|
||||
_client = client
|
||||
return _client
|
||||
|
||||
|
||||
def is_configured(username: Optional[str] = None) -> bool:
|
||||
user = (username or "daniele").lower()
|
||||
if user in MCP_USERS:
|
||||
key = f"LOOGLE_CASA_PASSWORD_{user.upper()}"
|
||||
if os.environ.get(key, "").strip():
|
||||
return True
|
||||
if os.environ.get("LOOGLE_CASA_PASSWORD", "").strip():
|
||||
return True
|
||||
return user in MCP_USERS
|
||||
|
||||
|
||||
def get_dashboard(username: str) -> dict:
|
||||
return _client_instance().get("/api/dashboard", username=username)
|
||||
|
||||
|
||||
def get_weather_home(username: str) -> dict:
|
||||
return _client_instance().get("/api/weather/home", username=username)
|
||||
|
||||
|
||||
def get_network_overview(username: str) -> dict:
|
||||
return _client_instance().get("/api/network/overview", username=username)
|
||||
|
||||
|
||||
def get_network_failover_status(username: str) -> dict:
|
||||
return _client_instance().get("/api/network/failover/status", username=username)
|
||||
|
||||
|
||||
def get_network_mcp_status(username: str) -> dict:
|
||||
return _client_instance().get("/api/network/mcp", username=username)
|
||||
|
||||
|
||||
def get_alerts_cards(username: str) -> Any:
|
||||
return _client_instance().get("/api/alerts/cards", username=username)
|
||||
Reference in new issue
Block a user