emcp/backend/app/schemas/platform.py

163 lines
3.5 KiB
Python
Raw Permalink Normal View History

2026-05-18 09:12:14 +08:00
from datetime import datetime
from typing import Dict, List, Optional
from pydantic import BaseModel, Field
class ValueGroup(BaseModel):
Ua: float = 0.0
Ub: float = 0.0
Uc: float = 0.0
Ia: float = 0.0
Ib: float = 0.0
Ic: float = 0.0
Pa: float = 0.0
Pb: float = 0.0
Pc: float = 0.0
Pt: float = 0.0
Qa: float = 0.0
Qb: float = 0.0
Qc: float = 0.0
Qt: float = 0.0
Sa: float = 0.0
Sb: float = 0.0
Sc: float = 0.0
St: float = 0.0
PFa: float = 0.0
PFb: float = 0.0
PFc: float = 0.0
PFt: float = 0.0
Uab: float = 0.0
Ubc: float = 0.0
Uca: float = 0.0
frq: float = 50.0
class LineData(BaseModel):
line_no: int
pri_val: ValueGroup = Field(default_factory=ValueGroup)
sec_val: ValueGroup = Field(default_factory=ValueGroup)
class RealtimeData(BaseModel):
line_list: List[LineData]
switch: Dict[str, int]
ai_collect: Dict[str, float]
class RealtimeEnvelope(BaseModel):
type: str = "real_time"
data: RealtimeData
class DeviceStatus(BaseModel):
self_check: str = "正常"
net1: str = "正常"
net2: str = "正常"
uart1: str = "正常"
uart2: str = "断开"
class HardwareVersion(BaseModel):
board_version: str = "B001.001.001"
display_version: str = "S001.001.001"
other_version: str = "Y001.001.001"
class SoftwareVersion(BaseModel):
display_program: str = "001.001.001"
communication_program: str = "001.001.001"
measurement_program: str = "001.001.001"
class NetConfigItem(BaseModel):
nic: str
ip: str = ""
mask: str = ""
gateway: str = ""
protocol: str = ""
class UartConfigItem(BaseModel):
port: str
baud: int = 9600
parity: str = "NONE"
data_bits: int = 8
stop_bits: int = 1
protocol: str = ""
class DeviceConfigIn(BaseModel):
password: str = "123456"
hardware_version: HardwareVersion = Field(default_factory=HardwareVersion)
software_version: SoftwareVersion = Field(default_factory=SoftwareVersion)
net: List[NetConfigItem] = Field(default_factory=list)
uart: List[UartConfigItem] = Field(default_factory=list)
class ChannelItem(BaseModel):
ch: int
singal_type: str
line_no: int
type: str
limit_low: float
limit_high: float
class ChannelConfigIn(BaseModel):
ai_channel: List[ChannelItem] = Field(default_factory=list)
ao_channel: List[ChannelItem] = Field(default_factory=list)
class AlarmRule(BaseModel):
category: str
limit: Optional[float] = None
delay: int = 0
output_node: str = ""
enabled: bool = True
class LineAlarmSettingIn(BaseModel):
line_no: int
over_limit_alarm: List[AlarmRule] = Field(default_factory=list)
fault_alarm: List[AlarmRule] = Field(default_factory=list)
class AiAlarmSettingIn(BaseModel):
channel_no: int
singal_type: str
limit_low: float
limit_high: float
delay: int = 0
output_node: str = ""
enabled: bool = True
class SystemConfigIn(BaseModel):
time_sync: str = "auto"
brightness: int = Field(default=80, ge=0, le=100)
screen_saver: int = Field(default=60, ge=0)
class PasswordVerifyIn(BaseModel):
password: str
2026-05-19 14:47:08 +08:00
class DevicePasswordUpdateIn(BaseModel):
password: str = Field(min_length=1)
2026-05-18 09:12:14 +08:00
class AlarmEvent(BaseModel):
id: Optional[int] = None
alarm_type: str
time: datetime
no: str = ""
type: str = ""
content: str
level: str = "一般"
class SwitchControlIn(BaseModel):
ch: int = Field(ge=1)
action: int = Field(ge=0, le=1)