Files
home-automation/app/config.py
T

51 lines
1.2 KiB
Python
Raw Normal View History

2026-04-19 20:19:58 +02:00
from functools import lru_cache
from pathlib import Path
from pydantic import computed_field
from pydantic_settings import BaseSettings, SettingsConfigDict
class Settings(BaseSettings):
app_name: str = "Home Automation Backend (Python)"
app_env: str = "development"
app_debug: bool = False
app_host: str = "0.0.0.0"
app_port: int = 8000
database_url: str = "sqlite:///./data/app.db"
ticktick_client_id: str = ""
ticktick_client_secret: str = ""
ticktick_redirect_uri: str = ""
ticktick_token: str = ""
home_assistant_base_url: str = ""
home_assistant_auth_token: str = ""
home_assistant_action_task_project_id: str = ""
model_config = SettingsConfigDict(
env_file=".env",
env_file_encoding="utf-8",
case_sensitive=False,
)
@computed_field
@property
def is_development(self) -> bool:
return self.app_env.lower() == "development"
@computed_field
@property
def sqlite_path(self) -> Path | None:
prefix = "sqlite:///"
if not self.database_url.startswith(prefix):
return None
raw_path = self.database_url[len(prefix) :]
return Path(raw_path)
@lru_cache
def get_settings() -> Settings:
return Settings()