2026-03-02 01:48:51 +01:00
|
|
|
"""Centralized configuration via environment variables."""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
import json
|
|
|
|
|
import os
|
|
|
|
|
from dataclasses import dataclass, field
|
|
|
|
|
from typing import List
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
|
class UnraidServer:
|
|
|
|
|
name: str
|
|
|
|
|
host: str
|
|
|
|
|
api_key: str = ""
|
|
|
|
|
port: int = 80
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
|
class Settings:
|
|
|
|
|
# --- Database (PostgreSQL) ---
|
|
|
|
|
db_host: str = "10.10.10.10"
|
|
|
|
|
db_port: int = 5433
|
|
|
|
|
db_name: str = "openclaw"
|
|
|
|
|
db_user: str = "sam"
|
|
|
|
|
db_password: str = "sam"
|
|
|
|
|
|
|
|
|
|
# --- Weather ---
|
|
|
|
|
weather_location: str = "Leverkusen"
|
|
|
|
|
weather_location_secondary: str = "Rab,Croatia"
|
|
|
|
|
weather_cache_ttl: int = 1800 # 30 min
|
|
|
|
|
|
|
|
|
|
# --- Home Assistant ---
|
|
|
|
|
ha_url: str = "https://homeassistant.daddelolymp.de"
|
|
|
|
|
ha_token: str = ""
|
|
|
|
|
ha_cache_ttl: int = 30
|
|
|
|
|
|
|
|
|
|
# --- Vikunja Tasks ---
|
|
|
|
|
vikunja_url: str = "http://10.10.10.10:3456/api/v1"
|
|
|
|
|
vikunja_token: str = ""
|
|
|
|
|
vikunja_cache_ttl: int = 60
|
|
|
|
|
|
|
|
|
|
# --- Unraid Servers ---
|
|
|
|
|
unraid_servers: List[UnraidServer] = field(default_factory=list)
|
|
|
|
|
unraid_cache_ttl: int = 15
|
|
|
|
|
|
|
|
|
|
# --- News ---
|
|
|
|
|
news_cache_ttl: int = 300 # 5 min
|
|
|
|
|
news_max_age_hours: int = 48
|
|
|
|
|
|
2026-03-02 10:13:50 +01:00
|
|
|
# --- MQTT ---
|
|
|
|
|
mqtt_host: str = ""
|
|
|
|
|
mqtt_port: int = 1883
|
|
|
|
|
mqtt_username: str = ""
|
|
|
|
|
mqtt_password: str = ""
|
|
|
|
|
mqtt_topics: List[str] = field(default_factory=lambda: ["#"])
|
|
|
|
|
mqtt_client_id: str = "daily-briefing"
|
|
|
|
|
|
2026-03-02 01:48:51 +01:00
|
|
|
# --- Server ---
|
|
|
|
|
host: str = "0.0.0.0"
|
|
|
|
|
port: int = 8080
|
|
|
|
|
debug: bool = False
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def from_env(cls) -> "Settings":
|
|
|
|
|
s = cls()
|
|
|
|
|
s.db_host = os.getenv("DB_HOST", s.db_host)
|
|
|
|
|
s.db_port = int(os.getenv("DB_PORT", str(s.db_port)))
|
|
|
|
|
s.db_name = os.getenv("DB_NAME", s.db_name)
|
|
|
|
|
s.db_user = os.getenv("DB_USER", s.db_user)
|
|
|
|
|
s.db_password = os.getenv("DB_PASSWORD", s.db_password)
|
|
|
|
|
|
|
|
|
|
s.weather_location = os.getenv("WEATHER_LOCATION", s.weather_location)
|
|
|
|
|
s.weather_location_secondary = os.getenv(
|
|
|
|
|
"WEATHER_LOCATION_SECONDARY", s.weather_location_secondary
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
s.ha_url = os.getenv("HA_URL", s.ha_url)
|
|
|
|
|
s.ha_token = os.getenv("HA_TOKEN", s.ha_token)
|
|
|
|
|
|
|
|
|
|
s.vikunja_url = os.getenv("VIKUNJA_URL", s.vikunja_url)
|
|
|
|
|
s.vikunja_token = os.getenv("VIKUNJA_TOKEN", s.vikunja_token)
|
|
|
|
|
|
2026-03-02 10:13:50 +01:00
|
|
|
s.mqtt_host = os.getenv("MQTT_HOST", s.mqtt_host)
|
|
|
|
|
s.mqtt_port = int(os.getenv("MQTT_PORT", str(s.mqtt_port)))
|
|
|
|
|
s.mqtt_username = os.getenv("MQTT_USERNAME", s.mqtt_username)
|
|
|
|
|
s.mqtt_password = os.getenv("MQTT_PASSWORD", s.mqtt_password)
|
|
|
|
|
s.mqtt_client_id = os.getenv("MQTT_CLIENT_ID", s.mqtt_client_id)
|
|
|
|
|
|
|
|
|
|
# Parse MQTT_TOPICS (comma-separated or JSON array)
|
|
|
|
|
raw_topics = os.getenv("MQTT_TOPICS", "")
|
|
|
|
|
if raw_topics:
|
|
|
|
|
try:
|
|
|
|
|
s.mqtt_topics = json.loads(raw_topics)
|
|
|
|
|
except (json.JSONDecodeError, TypeError):
|
|
|
|
|
s.mqtt_topics = [t.strip() for t in raw_topics.split(",") if t.strip()]
|
|
|
|
|
|
2026-03-02 01:48:51 +01:00
|
|
|
s.debug = os.getenv("DEBUG", "").lower() in ("1", "true", "yes")
|
|
|
|
|
|
|
|
|
|
# Parse UNRAID_SERVERS JSON
|
|
|
|
|
raw = os.getenv("UNRAID_SERVERS", "[]")
|
|
|
|
|
try:
|
|
|
|
|
servers_data = json.loads(raw)
|
|
|
|
|
s.unraid_servers = [
|
|
|
|
|
UnraidServer(
|
|
|
|
|
name=srv.get("name", f"Server {i+1}"),
|
|
|
|
|
host=srv.get("host", ""),
|
|
|
|
|
api_key=srv.get("api_key", ""),
|
|
|
|
|
port=int(srv.get("port", 80)),
|
|
|
|
|
)
|
|
|
|
|
for i, srv in enumerate(servers_data)
|
|
|
|
|
if srv.get("host")
|
|
|
|
|
]
|
|
|
|
|
except (json.JSONDecodeError, TypeError):
|
|
|
|
|
s.unraid_servers = []
|
|
|
|
|
|
|
|
|
|
return s
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
settings = Settings.from_env()
|