2236a8b3ee
改动:新增厂商推送配置、设备 push_vendor/push_token 字段、device push-test 接口、心跳超时厂商直推发送逻辑和对应测试。 验证:python -m pytest tests/test_device_push.py tests/test_auth.py tests/test_health.py 通过。
70 lines
1.9 KiB
Python
70 lines
1.9 KiB
Python
"""设备注册 / 心跳相关 schema(无障碍保护存活检测)。"""
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
|
|
from pydantic import BaseModel, ConfigDict, Field
|
|
|
|
|
|
class DeviceRegisterRequest(BaseModel):
|
|
device_id: str
|
|
# registration_id 为旧极光字段,新推送链路统一使用 push_vendor + push_token。
|
|
registration_id: str | None = None
|
|
push_vendor: str | None = None
|
|
push_token: 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
|
|
push_vendor: str | None = None
|
|
push_token: str | None = None
|
|
|
|
|
|
class DeviceOut(BaseModel):
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
id: int
|
|
device_id: str
|
|
registration_id: str | None
|
|
push_vendor: str | None
|
|
push_token: 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
|
|
|
|
|
|
class PushTestRequest(BaseModel):
|
|
device_id: str
|
|
delay_seconds: int = Field(default=10, ge=0, le=60)
|
|
push_vendor: str | None = None
|
|
push_token: str | None = None
|
|
registration_id: str | None = None
|
|
|
|
|
|
class PushTestOut(BaseModel):
|
|
ok: bool = True
|
|
delay_seconds: int
|
|
has_push_token: bool
|