From e88ddae6ca6ff92f147fd314b447536852166c76 Mon Sep 17 00:00:00 2001 From: impressionyang Date: Thu, 16 Apr 2026 09:48:31 +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?=E7=AC=AC=E4=BA=8C=E6=AC=A1=E4=BF=AE=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 | 71 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/问题修复记录.md b/问题修复记录.md index 4da1e3b..511882a 100644 --- a/问题修复记录.md +++ b/问题修复记录.md @@ -1,6 +1,75 @@ # 问题修复记录 -## 2026-04-16: 修复平台加载和 OptionsFlow 错误 +## 2026-04-16: 修复平台加载和 OptionsFlow 错误(第二次修复) + +### 问题描述 +平台文件设置时出现 `'NoneType' object has no attribute 'values'` 错误 + +### 错误日志 + +#### 错误 1: 平台文件访问 None 数据 +``` +AttributeError: 'NoneType' object has no attribute 'values' +File: sensor.py, line 40 +File: binary_sensor.py, line 37 +File: switch.py, line 34 +File: light.py, line 40 +File: device_tracker.py, line 34 +``` + +**原因**: `coordinator.data` 在初始化时为 `None` + +#### 错误 2: OptionsFlow 初始化错误 +``` +TypeError: SigMeshGatewayOptionsFlow() takes no arguments +File: config_flow.py, line 74 +``` + +**原因**: `async_get_options_flow` 是静态方法,传递了 `config_entry` 参数,但 `__init__` 不接受参数 + +### 解决方案 + +#### 修复 1: 平台文件添加 None 检查 +```python +async def async_setup_entry(...): + if coordinator.data is None: + _LOGGER.debug("协调器数据为空,等待设备数据") + return + + for device in coordinator.data.values(): + ... +``` + +#### 修复 2: 修复 async_get_options_flow +```python +@callback +def async_get_options_flow(self) -> SigMeshGatewayOptionsFlow: + """获取选项流程.""" + return SigMeshGatewayOptionsFlow() +``` + +#### 修复 3: OptionsFlow 添加 __init__ +```python +class SigMeshGatewayOptionsFlow(config_entries.OptionsFlow): + def __init__(self) -> None: + """初始化选项流程.""" + self._errors: dict[str, str] = {} +``` + +### 提交记录 +| Commit | 说明 | +|--------|------| +| 311cfbb | fix: 修复平台文件和 OptionsFlow 错误 | + +### 部署步骤 +```bash +cp -r custom_components/sigmesh_gateway ~/.homeassistant/custom_components/ +ha core restart +``` + +--- + +## 2026-04-16: 修复平台加载和 OptionsFlow 错误(第一次修复) ### 问题描述 配置集成时出现错误,无法加载平台实体