首先关于这个集成不了解的可以看这个帖子,是否有能方便的统计和显示日期倒数或耗材寿命的卡片? - 『HomeAssistant』求助&解答专区 - 『瀚思彼岸』» 智能家居技术论坛 - Powered by Discuz! (hassbian.com)
ha升级到2024.10后Anniversaries集成无法使用,后面去github找到解决办法,分享给需要的伙伴,只需要进入config\custom_components\anniversaries文件夹内,打开__init__.py文件(记事本打开也可以),将__init__.py文件内的内容全部删除,复制我下面提供的代码,粘贴到__init__.py文件内,保存__init__.py文件,之后整个系统全部重新重启,就可以正常使用了。
"""The Anniversaries Integration"""
import logging
from homeassistant import config_entries
from homeassistant.helpers import discovery
from integrationhelper.const import CC_STARTUP_VERSION
from .const import (
CONF_SENSORS,
CONF_DATE_TEMPLATE,
DOMAIN,
ISSUE_URL,
PLATFORM,
VERSION,
CONFIG_SCHEMA,
)
_LOGGER = logging.getLogger(__name__)
async def async_setup(hass, config):
"""Set up this component using YAML."""
if config.get(DOMAIN) is None:
# config flow setup
return True
# Log startup message
_LOGGER.info(
CC_STARTUP_VERSION.format(name=DOMAIN, version=VERSION, issue_link=ISSUE_URL)
)
platform_config = config[DOMAIN].get(CONF_SENSORS, {})
# If platform is not enabled, skip.
if not platform_config:
return False
for entry in platform_config:
hass.async_create_task(
discovery.async_load_platform(hass, PLATFORM, DOMAIN, entry, config)
)
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data={}
)
)
return True
async def async_setup_entry(hass, config_entry):
"""Set up this integration using UI."""
if config_entry.source == config_entries.SOURCE_IMPORT:
# Set up using YAML
hass.async_create_task(hass.config_entries.async_remove(config_entry.entry_id))
return False
# Log startup message
_LOGGER.info(
CC_STARTUP_VERSION.format(name=DOMAIN, version=VERSION, issue_link=ISSUE_URL)
)
# Update config entry options using async_update_entry
hass.config_entries.async_update_entry(
config_entry, options=config_entry.data
)
# Add update listener
config_entry.add_update_listener(update_listener)
# Forward setup to platform (e.g., sensor)
hass.async_add_job(
hass.config_entries.async_forward_entry_setup(config_entry, PLATFORM)
)
return True
async def async_remove_entry(hass, config_entry):
"""Handle removal of an entry."""
try:
await hass.config_entries.async_forward_entry_unload(config_entry, PLATFORM)
_LOGGER.info(
"Successfully removed sensor from the Anniversaries integration"
)
except ValueError:
pass
async def update_listener(hass, entry):
"""Update listener."""
entry.data = entry.options
await hass.config_entries.async_forward_entry_unload(entry, PLATFORM)
hass.async_add_job(hass.config_entries.async_forward_entry_setup(entry, PLATFORM))
|