59 lines
2.3 KiB
Python
59 lines
2.3 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
from dataclasses import dataclass
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class Settings:
|
|
ha_url: str | None = None
|
|
ha_token: str | None = None
|
|
model_store: str = ".model_store"
|
|
automation_store: str = ".automation_store"
|
|
actuator_store: str = ".actuator_store"
|
|
history_days: int = 14
|
|
min_training_points: int = 24
|
|
retrain_stale_hours: int = 24
|
|
reconcile_interval_seconds: int = 900
|
|
min_behavior_actions: int = 3
|
|
prediction_confidence: float = 0.82
|
|
prediction_window_minutes: int = 30
|
|
prediction_interval_seconds: int = 60
|
|
execution_cooldown_seconds: int = 900
|
|
timezone: str = "Europe/Berlin"
|
|
|
|
@property
|
|
def ha_configured(self) -> bool:
|
|
return bool(self.ha_url and self.ha_token)
|
|
|
|
|
|
def load_settings() -> Settings:
|
|
return Settings(
|
|
ha_url=os.getenv("SILLYHOME_HA_URL") or os.getenv("HA_URL"),
|
|
ha_token=os.getenv("SILLYHOME_HA_TOKEN") or os.getenv("HA_TOKEN"),
|
|
model_store=os.getenv("SILLYHOME_MODEL_STORE", ".model_store"),
|
|
automation_store=os.getenv("SILLYHOME_AUTOMATION_STORE", ".automation_store"),
|
|
actuator_store=os.getenv("SILLYHOME_ACTUATOR_STORE", ".actuator_store"),
|
|
history_days=max(1, min(31, int(os.getenv("SILLYHOME_HISTORY_DAYS", "14")))),
|
|
min_training_points=max(2, int(os.getenv("SILLYHOME_MIN_TRAINING_POINTS", "24"))),
|
|
retrain_stale_hours=max(1, int(os.getenv("SILLYHOME_RETRAIN_STALE_HOURS", "24"))),
|
|
reconcile_interval_seconds=max(
|
|
60, int(os.getenv("SILLYHOME_RECONCILE_INTERVAL_SECONDS", "900"))
|
|
),
|
|
min_behavior_actions=max(2, int(os.getenv("SILLYHOME_MIN_BEHAVIOR_ACTIONS", "3"))),
|
|
prediction_confidence=max(
|
|
0.5,
|
|
min(0.99, float(os.getenv("SILLYHOME_PREDICTION_CONFIDENCE", "0.82"))),
|
|
),
|
|
prediction_window_minutes=max(
|
|
5, min(120, int(os.getenv("SILLYHOME_PREDICTION_WINDOW_MINUTES", "30")))
|
|
),
|
|
prediction_interval_seconds=max(
|
|
30, int(os.getenv("SILLYHOME_PREDICTION_INTERVAL_SECONDS", "60"))
|
|
),
|
|
execution_cooldown_seconds=max(
|
|
60, int(os.getenv("SILLYHOME_EXECUTION_COOLDOWN_SECONDS", "900"))
|
|
),
|
|
timezone=os.getenv("SILLYHOME_TIMEZONE", "Europe/Berlin"),
|
|
)
|