feat: enhance MQTT integration checks in JackeryHome

- Added validation to ensure MQTT integration is configured before setting up the JackeryHome integration.
- Updated error handling in the configuration flow to provide user feedback if MQTT is not available.
- Improved logging for MQTT subscription processes and error handling in the data coordinator.
- Updated user interface strings to reflect the new requirements for MQTT integration.
This commit is contained in:
不求圣剑
2025-11-18 17:04:55 +08:00
parent e6afd02ff2
commit 0441a1ab38
5 changed files with 76 additions and 72 deletions

View File

@@ -4,6 +4,7 @@ import logging
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.const import Platform
from homeassistant.components import mqtt
_LOGGER = logging.getLogger(__name__)
@@ -15,6 +16,17 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up JackeryHome from a config entry."""
_LOGGER.info("Setting up JackeryHome integration")
# 检查 MQTT 集成是否已配置和可用
if not await mqtt.async_wait_for_mqtt_client(hass):
_LOGGER.error(
"MQTT integration is not available or not configured. "
"Please set up the MQTT integration first: "
"Settings -> Devices & Services -> Add Integration -> MQTT"
)
return False
_LOGGER.info("MQTT integration is available and ready")
# 初始化存储结构
hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][entry.entry_id] = {