0964d81898
- 表/类改名 device→device_liveness / Device→DeviceLiveness:该表记的是无障碍存活监控状态 (心跳/liveness_state/kill_alert_pending/推送目标),非设备信息(品牌/型号),原名误导。同步改 建表迁移表名/索引/约束(未部署→直接改建表迁移,非加 rename);API 路径 /api/v1/device 不变。 - GET /device/liveness 的 LivenessOut 只返 kill_alert_pending 一个布尔(原返回 liveness_state/ ever_protected/last_heartbeat_at 等设备详情);前端本就只读 kill_alert_pending,不受影响。
49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
"""设备注册 / 心跳相关 schema(无障碍保护存活检测)。"""
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
|
|
from pydantic import BaseModel, ConfigDict
|
|
|
|
|
|
class DeviceRegisterRequest(BaseModel):
|
|
device_id: str
|
|
registration_id: str | None = None
|
|
platform: str = "android"
|
|
app_version: str | None = None
|
|
|
|
|
|
class HeartbeatRequest(BaseModel):
|
|
device_id: str
|
|
source: str = "service" # service | app
|
|
accessibility_enabled: bool = True
|
|
registration_id: str | None = None
|
|
|
|
|
|
class DeviceOut(BaseModel):
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
id: int
|
|
device_id: str
|
|
registration_id: str | None
|
|
ever_protected: bool
|
|
liveness_state: str
|
|
last_heartbeat_at: datetime | None
|
|
updated_at: datetime | None
|
|
|
|
|
|
class OkResponse(BaseModel):
|
|
ok: bool = True
|
|
|
|
|
|
class LivenessOut(BaseModel):
|
|
"""本机掉线告警状态(后置检测 pull 版)。客户端只需这一个布尔判断要不要弹「开启自启动」引导,
|
|
故只返回 kill_alert_pending(不暴露设备详情 / 内部 liveness_state 等)。从未注册过 → 默认 False(无告警)。"""
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
kill_alert_pending: bool = False
|
|
|
|
|
|
class LivenessAckRequest(BaseModel):
|
|
device_id: str
|