diff --git a/custom_components/sigmesh_gateway/binary_sensor.py b/custom_components/sigmesh_gateway/binary_sensor.py index 3e5d717..cd37120 100644 --- a/custom_components/sigmesh_gateway/binary_sensor.py +++ b/custom_components/sigmesh_gateway/binary_sensor.py @@ -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: diff --git a/custom_components/sigmesh_gateway/config_flow.py b/custom_components/sigmesh_gateway/config_flow.py index 2ec74b3..1b4e78b 100644 --- a/custom_components/sigmesh_gateway/config_flow.py +++ b/custom_components/sigmesh_gateway/config_flow.py @@ -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: diff --git a/custom_components/sigmesh_gateway/device_tracker.py b/custom_components/sigmesh_gateway/device_tracker.py index d61b4ca..c2067a2 100644 --- a/custom_components/sigmesh_gateway/device_tracker.py +++ b/custom_components/sigmesh_gateway/device_tracker.py @@ -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)) diff --git a/custom_components/sigmesh_gateway/light.py b/custom_components/sigmesh_gateway/light.py index 41b4d6b..977fc26 100644 --- a/custom_components/sigmesh_gateway/light.py +++ b/custom_components/sigmesh_gateway/light.py @@ -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): diff --git a/custom_components/sigmesh_gateway/sensor.py b/custom_components/sigmesh_gateway/sensor.py index d925184..c7da7f8 100644 --- a/custom_components/sigmesh_gateway/sensor.py +++ b/custom_components/sigmesh_gateway/sensor.py @@ -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: diff --git a/custom_components/sigmesh_gateway/switch.py b/custom_components/sigmesh_gateway/switch.py index f1ada79..90395d3 100644 --- a/custom_components/sigmesh_gateway/switch.py +++ b/custom_components/sigmesh_gateway/switch.py @@ -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 模型