fix: 修复平台文件和 OptionsFlow 错误

修复内容:
1. 所有平台文件添加 coordinator.data None 检查
   - sensor.py, binary_sensor.py, switch.py, light.py, device_tracker.py
2. 修复 async_get_options_flow 签名
   - 改为实例方法,移除 config_entry 参数
   - 移除 @staticmethod 装饰器
3. OptionsFlow 添加正确的 __init__ 方法

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
impressionyang 2026-04-16 09:48:00 +08:00
parent 28e9800cae
commit 311cfbbe7e
6 changed files with 27 additions and 5 deletions

View File

@ -34,6 +34,10 @@ async def async_setup_entry(
entities: list[SigMeshBinarySensor] = []
if coordinator.data is None:
_LOGGER.debug("协调器数据为空,等待设备数据")
return
for device in coordinator.data.values():
# 检测是否存在开关状态
if device.states.get("onoff") is not None:

View File

@ -6,7 +6,6 @@ from typing import Any
import voluptuous as vol
from homeassistant import config_entries
from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers import selector
@ -65,18 +64,21 @@ class SigMeshGatewayConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
errors=errors,
)
@staticmethod
@callback
def async_get_options_flow(
config_entry: config_entries.ConfigEntry,
self,
) -> SigMeshGatewayOptionsFlow:
"""获取选项流程."""
return SigMeshGatewayOptionsFlow(config_entry)
return SigMeshGatewayOptionsFlow()
class SigMeshGatewayOptionsFlow(config_entries.OptionsFlow):
"""SigMesh Gateway 选项流程."""
def __init__(self) -> None:
"""初始化选项流程."""
self._errors: dict[str, str] = {}
async def async_step_init(self, user_input: dict[str, Any] | None = None) -> FlowResult:
"""管理选项."""
if user_input is not None:

View File

@ -31,6 +31,10 @@ async def async_setup_entry(
entities: list[SigMeshDeviceTracker] = []
if coordinator.data is None:
_LOGGER.debug("协调器数据为空,等待设备数据")
return
for device in coordinator.data.values():
entities.append(SigMeshDeviceTracker(coordinator, device))

View File

@ -37,6 +37,10 @@ async def async_setup_entry(
entities: list[SigMeshLight] = []
if coordinator.data is None:
_LOGGER.debug("协调器数据为空,等待设备数据")
return
for device in coordinator.data.values():
# 检查是否为灯光设备
if device.model_id in (0x1300, 0x1307, 0x130C, 0x130D):

View File

@ -36,7 +36,11 @@ async def async_setup_entry(
# 创建传感器实体
entities: list[SigMeshSensor] = []
# 从协调器获取设备
# 从协调器获取设备(检查 data 是否为 None
if coordinator.data is None:
_LOGGER.debug("协调器数据为空,等待设备数据")
return
for device in coordinator.data.values():
# 根据设备状态创建相应的传感器
if device.states.get("property_id") is not None:

View File

@ -31,6 +31,10 @@ async def async_setup_entry(
entities: list[SigMeshSwitch] = []
if coordinator.data is None:
_LOGGER.debug("协调器数据为空,等待设备数据")
return
for device in coordinator.data.values():
# 检查是否为开关设备
if device.model_id == 0x1000: # OnOff Server 模型