Обновить custom_components/motion_recorder/__init__.py
This commit is contained in:
@@ -11,9 +11,13 @@ _LOGGER = logging.getLogger(__name__)
|
||||
PLATFORMS = ["sensor", "switch"]
|
||||
|
||||
|
||||
def _get_config_value(entry: ConfigEntry, key: str, default=None):
|
||||
"""Get config value from options first, then from data, then default."""
|
||||
return entry.options.get(key, entry.data.get(key, default))
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up Motion Recorder from a config entry."""
|
||||
# Устанавливаем уровень логирования для всего домена
|
||||
log_level = _get_config_value(entry, CONF_LOG_LEVEL, DEFAULT_LOG_LEVEL)
|
||||
logging.getLogger(f"custom_components.{DOMAIN}").setLevel(getattr(logging, log_level, logging.INFO))
|
||||
_LOGGER.info("Motion Recorder integration loaded with log level: %s", log_level)
|
||||
@@ -27,7 +31,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
|
||||
# Добавляем listener для автоматической перезагрузки при изменении опций
|
||||
entry.async_on_unload(entry.add_update_listener(_async_update_listener))
|
||||
|
||||
return True
|
||||
@@ -50,8 +53,3 @@ async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry) -> Non
|
||||
"""Handle options update - reload the integration."""
|
||||
_LOGGER.info("Options updated, reloading Motion Recorder integration")
|
||||
await hass.config_entries.async_reload(entry.entry_id)
|
||||
|
||||
|
||||
def _get_config_value(entry: ConfigEntry, key: str, default=None):
|
||||
"""Get config value from options first, then from data, then default."""
|
||||
return entry.options.get(key, entry.data.get(key, default))
|
||||
Reference in New Issue
Block a user