SmartEDT/backend/device/base.py

37 lines
820 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""设备抽象层。
用于统一不同设备真实硬件、仿真设备、Mock的连接与状态查询接口。
"""
from __future__ import annotations
from dataclasses import dataclass
@dataclass(frozen=True)
class DeviceInfo:
"""设备信息快照(可用于 API 输出)。"""
device_id: str
device_type: str
connected: bool
class DeviceAdapter:
"""设备适配器接口(异步)。"""
device_id: str
device_type: str
async def connect(self) -> None:
"""建立与设备的连接。"""
raise NotImplementedError
async def disconnect(self) -> None:
"""断开与设备的连接。"""
raise NotImplementedError
async def is_connected(self) -> bool:
"""返回当前连接状态。"""
raise NotImplementedError