SuperAPI AI 工具集

ha-diagnostics

编程与开发

查看项目

更新于 10-15 23:48

技能介绍

用途:为 Home Assistant 集成实现诊断支持,向用户和开发者提供结构化调试信息,同时对敏感数据脱敏。该功能是集成质量等级(Integration Quality Scale)中 Gold 级别的必备项。

文件结构:诊断代码放在 custom_components/{domain}/diagnostics.py 中,与 init.py 同目录。

主要能力:提供基础与进阶两种诊断模板。基础模板从 homeassistant.components.diagnostics 导入 async_redact_data,实现 async_get_config_entry_diagnostics(hass, entry),返回经过脱敏的 config_entry 与 coordinator 数据。进阶模板还会读取设备与实体注册表(device_registry、entity_registry),输出设备名称、型号、厂商、软硬件版本及实体列表,并附带协调器的 last_update_success、last_exception、update_interval 等信息。可选实现 async_get_device_diagnostics 提供按设备的诊断,适合中枢型集成。

脱敏规则:务必脱敏认证类(password、token、api_key、access_token、refresh_token、secret、credentials、auth)、个人信息(email、username、user_id、account_id)、设备标识(serial、serial_number、unique_id、mac、mac_address)、位置(latitude、longitude、location、address、coordinates),酌情处理网络信息(ip_address、ip、ssid)。不应脱敏型号、固件版本、功能开关、错误信息、时间戳及不含个人信息的实体状态。async_redact_data 会递归将匹配键替换为 REDACTED;也可编写自定义函数(如用正则清理 URL 中的 token)。

使用与测试:资料仅为模板与示例代码,未提供安装命令或调用方式;测试示例展示如何断言 config_entry 与 coordinator_data 存在,并校验敏感字段已被替换为 REDACTED。

相关技能:配置项(ha-config-flow)、协调器(ha-coordinator)、质量审查(ha-quality-review)。

限制:资料未说明具体平台版本要求、插件安装步骤或收费信息,相关事实暂未提供。