AI生成代码
This commit is contained in:
50
core/base_handler.py
Normal file
50
core/base_handler.py
Normal file
@@ -0,0 +1,50 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
|
||||
class BaseHandler(ABC):
|
||||
"""
|
||||
命令处理器抽象基类
|
||||
定义所有命令处理器需要实现的基本方法
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def handle_command(self, command: str, data: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
||||
"""
|
||||
处理命令
|
||||
|
||||
Args:
|
||||
command: 命令类型
|
||||
data: 命令数据
|
||||
|
||||
Returns:
|
||||
Dict[str, Any]: 处理结果
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def register_command(self, command: str, handler_func) -> bool:
|
||||
"""
|
||||
注册命令处理函数
|
||||
|
||||
Args:
|
||||
command: 命令类型
|
||||
handler_func: 处理函数
|
||||
|
||||
Returns:
|
||||
bool: 注册是否成功
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def unregister_command(self, command: str) -> bool:
|
||||
"""
|
||||
注销命令处理函数
|
||||
|
||||
Args:
|
||||
command: 命令类型
|
||||
|
||||
Returns:
|
||||
bool: 注销是否成功
|
||||
"""
|
||||
pass
|
||||
43
core/enums.py
Normal file
43
core/enums.py
Normal file
@@ -0,0 +1,43 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class LogLevel(Enum):
|
||||
"""日志等级枚举"""
|
||||
DEBUG = "DEBUG"
|
||||
INFO = "INFO"
|
||||
WARNING = "WARNING"
|
||||
ERROR = "ERROR"
|
||||
CRITICAL = "CRITICAL"
|
||||
|
||||
|
||||
class DeviceType(Enum):
|
||||
"""设备类型枚举"""
|
||||
# 传感器类型
|
||||
TEMPERATURE = "temperature"
|
||||
HUMIDITY = "humidity"
|
||||
PRESSURE = "pressure"
|
||||
LIGHT = "light"
|
||||
CO2 = "co2"
|
||||
NH3 = "nh3" # 氨气
|
||||
H2S = "h2s" # 硫化氢
|
||||
|
||||
# 执行器类型
|
||||
FEED_PORT = "feed_port"
|
||||
WATER_VALVE = "water_valve"
|
||||
FAN = "fan"
|
||||
HEATER = "heater"
|
||||
COOLER = "cooler"
|
||||
LIGHT_CONTROLLER = "light_controller"
|
||||
|
||||
|
||||
class BusType(Enum):
|
||||
"""总线类型枚举"""
|
||||
SENSOR = "sensor"
|
||||
ACTUATOR = "actuator"
|
||||
|
||||
|
||||
class ErrorHandlingStrategy(Enum):
|
||||
"""错误处理策略枚举"""
|
||||
RETRY = "retry"
|
||||
SKIP = "skip"
|
||||
ALERT = "alert"
|
||||
Reference in New Issue
Block a user