e66f7fed8c
- wx_poc_signal 进程内存信号(device_id→source), 只对 WX_POC_TEST_DEVICE_ID 生效 - 收图 image → set_pending(测试设备, meituan) - POST /device/heartbeat 返回 HeartbeatResponse, 该设备有信号则带回 pending_compare 并清除 - 心跳 schema OkResponse→HeartbeatResponse, 老前端不读 body 向后兼容 - WX_POC_TEST_DEVICE_ID 空=不触发任何设备(部署零风险, 待填测试机 id) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
63 lines
1.8 KiB
Python
63 lines
1.8 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 PendingCompare(BaseModel):
|
|
"""PoC:后端通过心跳下发的"用户要从某源平台比价"信号。前端据此弹选平台窗 + launch 源平台。"""
|
|
source_platform: str # pricebot 源平台代号(PoC 写死 "meituan")
|
|
source_package: str # 源平台 Android 包名(前端 launch 用)
|
|
|
|
|
|
class HeartbeatResponse(BaseModel):
|
|
"""心跳响应。常规只回 ok;PoC 期带回 pending_compare 触发比价(exclude_none 省略 null)。"""
|
|
model_config = ConfigDict()
|
|
|
|
ok: bool = True
|
|
pending_compare: PendingCompare | None = None
|
|
|
|
|
|
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
|