mirror of
https://github.com/MarekWo/mc-webui.git
synced 2026-08-08 01:32:54 +02:00
feat: Auto-detect device name from meshcli prompt
Bridge now detects device name from meshcli prompt ("DeviceName|*")
and exposes it via /health endpoint. mc-webui fetches this at startup
and uses RuntimeConfig for dynamic device name throughout the app.
Fallback chain: prompt detection → .infos command → MC_DEVICE_NAME env var
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,11 @@ Configuration module - loads settings from environment variables
|
||||
"""
|
||||
|
||||
import os
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Config:
|
||||
@@ -51,3 +55,40 @@ class Config:
|
||||
|
||||
# Global config instance
|
||||
config = Config()
|
||||
|
||||
|
||||
class RuntimeConfig:
|
||||
"""
|
||||
Runtime configuration that can be updated after startup.
|
||||
|
||||
Used for values that are detected/fetched at runtime, like
|
||||
device name from bridge auto-detection.
|
||||
"""
|
||||
_device_name: Optional[str] = None
|
||||
_device_name_source: str = "config"
|
||||
|
||||
@classmethod
|
||||
def set_device_name(cls, name: str, source: str = "detected"):
|
||||
"""Set the runtime device name"""
|
||||
cls._device_name = name
|
||||
cls._device_name_source = source
|
||||
logger.info(f"Runtime device name set: {name} (source: {source})")
|
||||
|
||||
@classmethod
|
||||
def get_device_name(cls) -> str:
|
||||
"""Get device name - prefers runtime value, falls back to config"""
|
||||
return cls._device_name or config.MC_DEVICE_NAME
|
||||
|
||||
@classmethod
|
||||
def get_device_name_source(cls) -> str:
|
||||
"""Get the source of the device name (detected/config/fallback)"""
|
||||
return cls._device_name_source
|
||||
|
||||
@classmethod
|
||||
def get_msgs_file_path(cls) -> Path:
|
||||
"""Get the full path to the .msgs file using runtime device name"""
|
||||
return Path(config.MC_CONFIG_DIR) / f"{cls.get_device_name()}.msgs"
|
||||
|
||||
|
||||
# Global runtime config instance
|
||||
runtime_config = RuntimeConfig()
|
||||
|
||||
Reference in New Issue
Block a user