- 重写 sensor.py,使用 Home Assistant 内置 MQTT 组件 - 修复配置流程标题显示 - 添加更好的错误处理和日志记录 - 创建 MQTT 测试脚本 - 统一所有日志信息为 JackeryHome
40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
"""Energy Monitor MQTT Integration for Home Assistant."""
|
|
import logging
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.const import Platform
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
DOMAIN = "jackery_home"
|
|
PLATFORMS = [Platform.SENSOR]
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
"""Set up JackeryHome from a config entry."""
|
|
_LOGGER.info("Setting up JackeryHome integration")
|
|
|
|
# 存储配置数据
|
|
hass.data.setdefault(DOMAIN, {})
|
|
hass.data[DOMAIN][entry.entry_id] = entry.data
|
|
|
|
# 加载传感器平台
|
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
|
|
|
return True
|
|
|
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
"""Unload a config entry."""
|
|
_LOGGER.info("Unloading JackeryHome integration")
|
|
|
|
# 卸载传感器平台
|
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
|
|
|
if unload_ok:
|
|
hass.data[DOMAIN].pop(entry.entry_id)
|
|
|
|
return unload_ok
|
|
|