refactor: 全面重构腾讯云人脸识别插件

- 拆分 tencent_cloud_client.py(1311行)为 api_operations.py / image_processor.py / retry.py
- 更新 HA 废弃 API: SupportsResponse.OPTIONAL, async_unload_platforms, native_value, 移除 CONNECTION_CLASS
- 新增动态人员传感器管理(自动增/删)
- 新增 detect_face 服务定义(services.yaml)
- 移除 secret_key 持久化存储,增强安全性
- 完善错误映射前缀匹配 + 异常类型安全退避
- 修复 Coordinator 双重人员 ID 跟踪死代码
- 添加 _sanitize_error 脱敏,ImageCache LRU 缓存
- manifest.json 版本 2.1.0 + Pillow 依赖
This commit is contained in:
Hermes
2026-07-07 02:33:38 +08:00
parent 14c2e56656
commit 18a6a8ca9b
15 changed files with 1829 additions and 1345 deletions
+6 -3
View File
@@ -53,7 +53,6 @@ class FaceRecognition:
image_file,
)
raise ValueError("必须提供image_url、image_path、image_file或camera_entity_id")
async def _get_camera_image_base64(self, camera_entity_id: str) -> str:
try:
from homeassistant.components.camera import async_get_image
@@ -151,11 +150,13 @@ class FaceRecognition:
return result
def _process_search_results(self, results: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
"""规范化搜索结果字段(保留客户端返回的全部信息)。"""
processed_results = []
for result in results:
processed_result = {
"face_id": result.get("face_id"),
"candidates": []
"face_rect": result.get("face_rect"),
"candidates": [],
}
for candidate in result.get("candidates", []):
@@ -163,7 +164,9 @@ class FaceRecognition:
"person_id": candidate.get("person_id"),
"person_name": candidate.get("person_name"),
"score": candidate.get("score"),
"person_tag": candidate.get("person_tag")
"face_id": candidate.get("face_id"),
"gender": candidate.get("gender"),
"person_group_infos": candidate.get("person_group_infos", []),
}
processed_result["candidates"].append(processed_candidate)