"""固件管理的出入参。""" from __future__ import annotations import uuid from datetime import datetime from pydantic import BaseModel, ConfigDict, Field class FirmwareOut(BaseModel): model_config = ConfigDict(from_attributes=True) id: uuid.UUID model: str version: str channel: str size_bytes: int sha256: str notes: str = "" notes_en: str = "" min_version: str = "" published: bool download_count: int = 0 created_at: datetime | None = None published_at: datetime | None = None # 运行时补的统计:这个版本上跑着多少台设备 device_count: int = 0 class FirmwarePatch(BaseModel): notes: str | None = None notes_en: str | None = None channel: str | None = Field(default=None, pattern="^(stable|beta)$") min_version: str | None = None published: bool | None = None class UploadForm(BaseModel): """multipart 表单里的文本字段(FastAPI 用 Form(...) 逐个取,这里只作说明与校验)。""" version: str model: str = "JC3636K518C_I_W" channel: str = "stable" notes: str = "" notes_en: str = "" min_version: str = "" publish: bool = False class UpgradeIn(BaseModel): firmware_id: uuid.UUID class RolloutIn(BaseModel): firmware_id: uuid.UUID # 不传 = 所有低于该版本的设备;传了只推给这些设备 device_ids: list[uuid.UUID] | None = None include_offline: bool = True class DeviceUpgradeOut(BaseModel): id: uuid.UUID chip_id: str model: str fw_version: str target_version: str = "" upgrade_state: str = "" upgrade_error: str = "" upgrade_at: datetime | None = None boot_slot: str = "" fw_updated_at: datetime | None = None bound_user_id: uuid.UUID | None = None user_label: str = "" last_active_at: datetime | None = None class CheckOut(BaseModel): update: bool version: str = "" size: int = 0 sha256: str = "" notes: str = "" url: str = "" mandatory: bool = False reason: str = ""