From 28e9800caeab85bd83ef84351995cb4f0e8678e0 Mon Sep 17 00:00:00 2001 From: impressionyang Date: Thu, 16 Apr 2026 09:40:05 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E6=9B=B4=E6=96=B0=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AE=B0=E5=BD=95=20-=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E5=8A=A0=E8=BD=BD=E9=94=99=E8=AF=AF=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.6 --- 问题修复记录.md | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/问题修复记录.md b/问题修复记录.md index 8492d69..4da1e3b 100644 --- a/问题修复记录.md +++ b/问题修复记录.md @@ -1,5 +1,75 @@ # 问题修复记录 +## 2026-04-16: 修复平台加载和 OptionsFlow 错误 + +### 问题描述 +配置集成时出现错误,无法加载平台实体 + +### 错误日志 + +#### 错误 1: 平台模块加载失败 +``` +ModuleNotFoundError: No module named 'custom_components.sigmesh_gateway.sensor' +``` + +**原因**: 平台文件放在 `platforms/` 子目录中,但 HA 期望平台文件直接在集成根目录下 + +#### 错误 2: OptionsFlow config_entry 错误 +``` +AttributeError: property 'config_entry' of 'SigMeshGatewayOptionsFlow' object has no setter +``` + +**原因**: 新版 HA 中 OptionsFlow 自动提供 `self.config_entry`,不需要手动设置 + +### 解决方案 + +#### 修复 1: 移动平台文件到集成根目录 +```bash +# 从 platforms/ 移到根目录 +mv platforms/sensor.py . +mv platforms/binary_sensor.py . +mv platforms/switch.py . +mv platforms/light.py . +mv platforms/device_tracker.py . +rmdir platforms +``` + +#### 修复 2: 修复 OptionsFlow +```diff +class SigMeshGatewayOptionsFlow(config_entries.OptionsFlow): + """SigMesh Gateway 选项流程.""" + +- def __init__(self, config_entry: config_entries.ConfigEntry) -> None: +- """初始化选项流程.""" +- self.config_entry = config_entry + + async def async_step_init(self, user_input: dict[str, Any] | None = None) -> FlowResult: +``` + +#### 修复 3: 添加集成图标 +- 复制图标到 `custom_components/sigmesh_gateway/icons/icon.png` +- HA 会自动识别该图标并显示在集成页面 + +### 提交记录 +| Commit | 说明 | +|--------|------| +| 19774a4 | fix: 修复平台加载和 OptionsFlow 错误 | + +### 部署步骤 +```bash +# 复制更新后的集成文件 +cp -r /home/ubuntu/workspace/cherry-studio/enginneer/impress_sig_mesh_hacs/custom_components/sigmesh_gateway \ + /custom_components/ + +# 重启 Home Assistant +ha core restart +``` + +### 验证 +重启后,在 HA UI 中重新尝试添加集成,应能正常显示配置表单和创建实体。 + +--- + ## 2026-04-15: 修复配置向导 500 错误 ### 问题描述