move_detect/edge/config.py

43 lines
1.4 KiB
Python

from dataclasses import dataclass
from edge.detectors.fall import FallConfig
from edge.detectors.immobility import ImmobilityConfig
from edge.detectors.ghost import GhostConfig
from edge.detectors.zone import ZoneConfig
from edge.engine import EngineConfig
@dataclass
class Config:
device_id: str
camera_id: str
cafe24_url: str
secret: str
fall: FallConfig
immobility: ImmobilityConfig
ghost: GhostConfig
zone: ZoneConfig
engine: EngineConfig
def _f(env: dict, key: str, default: float) -> float:
return float(env[key]) if key in env else default
def load_config(env: dict) -> Config:
camera_id = env.get("CAMERA_ID", "cam-01")
fall = FallConfig(
prone_confirm_s=_f(env, "FALL_PRONE_S", 3.0),
no_motion_s=_f(env, "FALL_NO_MOTION_S", 10.0),
)
immobility = ImmobilityConfig(immobile_s=_f(env, "IMMOBILE_S", 120.0))
ghost = GhostConfig(reappear_s=_f(env, "GHOST_REAPPEAR_S", 10.0))
zone = ZoneConfig(debounce_s=_f(env, "ZONE_DEBOUNCE_S", 0.75))
engine = EngineConfig(camera_id=camera_id, cooldown_s=_f(env, "COOLDOWN_S", 30.0))
return Config(
device_id=env.get("DEVICE_ID", "pi-unknown"),
camera_id=camera_id,
cafe24_url=env.get("CAFE24_URL", ""),
secret=env.get("DEVICE_SECRET", ""),
fall=fall, immobility=immobility, ghost=ghost, zone=zone, engine=engine,
)