Files
solar-pv-dashboard/backend/app/core_settings.py
Mateusz Gruszczyński c5cc2efbac first commit
2026-03-23 15:56:18 +01:00

72 lines
2.0 KiB
Python

from __future__ import annotations
from dataclasses import dataclass
from functools import lru_cache
import config
from app.models.definitions import MetricDefinition
@dataclass(frozen=True)
class AppSettings:
app_name: str
version: str
debug: bool
api_prefix: str
timezone: str
host: str
port: int
site_name: str
installed_power_kwp: float
co2_factor: float
influx: dict
storage: dict
cors_origins: list[str]
modules: dict
realtime: dict
time_ranges: dict
analytics: dict
history: dict
strings: list[dict]
status_metrics: list[str]
visible_entity_table: list[str]
frontend_defaults: dict
auth: dict
i18n: dict
metrics: dict[str, MetricDefinition]
@lru_cache(maxsize=1)
def get_settings() -> AppSettings:
metric_catalog = {
metric_id: MetricDefinition(id=metric_id, **payload)
for metric_id, payload in config.METRICS.items()
}
return AppSettings(
app_name=config.APP_CONFIG["name"],
version=config.APP_CONFIG["version"],
debug=config.APP_CONFIG["debug"],
api_prefix=config.APP_CONFIG["api_prefix"],
timezone=config.APP_CONFIG["timezone"],
host=config.APP_CONFIG["host"],
port=config.APP_CONFIG["port"],
site_name=config.SITE_CONFIG["site_name"],
installed_power_kwp=config.SITE_CONFIG["installed_power_kwp"],
co2_factor=config.SITE_CONFIG["co2_factor_kg_per_kwh"],
influx=config.INFLUXDB_CONFIG,
storage=config.STORAGE_CONFIG,
cors_origins=config.CORS_ORIGINS,
modules=config.MODULES,
realtime=config.REALTIME,
time_ranges=config.TIME_RANGES,
analytics=config.ANALYTICS,
history=config.HISTORY,
strings=config.STRINGS,
status_metrics=config.STATUS_METRICS,
visible_entity_table=config.VISIBLE_ENTITY_TABLE,
frontend_defaults=config.FRONTEND_DEFAULTS,
auth=config.AUTH_CONFIG,
i18n=config.I18N,
metrics=metric_catalog,
)