You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
2.3 KiB

"""
应用配置管理模块
"""
import os
from typing import Optional
from pydantic_settings import BaseSettings
class AdbConfig(BaseSettings):
"""ADB配置类"""
# ADB服务器配置
adb_host: str = "127.0.0.1"
adb_port: int = 5037
# 连接配置
connection_timeout: int = 30
retry_attempts: int = 3
retry_delay: float = 1.0
# 设备监控配置
device_monitor_interval: float = 1.0
device_monitor_enabled: bool = True
# 日志配置
log_level: str = "INFO"
log_format: str = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
class Config:
env_prefix = "ADB_"
env_file = ".env"
class WebSocketConfig(BaseSettings):
"""WebSocket配置类"""
# SSL配置
ssl_verify_certificate: bool = False # 是否验证SSL证书(开发环境建议设为False)
ssl_verify_hostname: bool = False # 是否验证主机名(开发环境建议设为False)
# 连接配置
connection_timeout: int = 60 # 增加连接超时时间到60秒
reconnect_attempts: int = 5
reconnect_delay: float = 1.0
# 心跳配置
heartbeat_interval: int = 120 # 默认2分钟,与日志中的描述一致
class Config:
env_prefix = "WEBSOCKET_"
env_file = ".env"
class AppConfig(BaseSettings):
"""应用配置类"""
# 应用基本信息
app_name: str = "TermControlAgent"
app_version: str = "1.0.0"
debug: bool = False
# 服务器配置
host: str = "0.0.0.0"
port: int = 8000
# 数据库配置
database_url: Optional[str] = None
# 安全配置
secret_key: str = "your-secret-key-here"
access_token_expire_minutes: int = 30
# CORS配置
allowed_origins: list = ["*"]
cors_enabled: bool = True
# ADB配置
adb: AdbConfig = AdbConfig()
# WebSocket配置
websocket: WebSocketConfig = WebSocketConfig()
class Config:
env_prefix = "APP_"
env_file = ".env"
# 全局配置实例
config = AppConfig()
# 协议类型枚举
class ProtocolType:
ADB = "adb"
ATX = "atx"
HDC = "hdc"
AT = "at"
PLNK = "plnk"
SSH = "ssh"
# 设备状态枚举
class DeviceStatus:
ONLINE = "online"
OFFLINE = "offline"
BUSY = "busy"
ERROR = "error"