From 9962301b42dcba5705879a270c3e56c77cbb92b4 Mon Sep 17 00:00:00 2001 From: Jan Bouwhuis Date: Fri, 24 Nov 2023 21:34:09 +0100 Subject: [PATCH] Do not notify config errors during logging (#104466) --- homeassistant/bootstrap.py | 2 ++ homeassistant/components/device_tracker/legacy.py | 7 ++++++- homeassistant/components/template/config.py | 6 +++++- homeassistant/config.py | 5 ----- tests/test_bootstrap.py | 2 +- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/homeassistant/bootstrap.py b/homeassistant/bootstrap.py index 4e0a0a5dd44..0998ac6274c 100644 --- a/homeassistant/bootstrap.py +++ b/homeassistant/bootstrap.py @@ -41,6 +41,7 @@ from .setup import ( DATA_SETUP, DATA_SETUP_STARTED, DATA_SETUP_TIME, + async_notify_setup_error, async_set_domains_to_be_loaded, async_setup_component, ) @@ -293,6 +294,7 @@ async def async_from_config_dict( await conf_util.async_process_ha_core_config(hass, core_config) except vol.Invalid as config_err: conf_util.async_log_schema_error(config_err, core.DOMAIN, core_config, hass) + async_notify_setup_error(hass, core.DOMAIN) return None except HomeAssistantError: _LOGGER.error( diff --git a/homeassistant/components/device_tracker/legacy.py b/homeassistant/components/device_tracker/legacy.py index b893654e8cd..f18f7984e1e 100644 --- a/homeassistant/components/device_tracker/legacy.py +++ b/homeassistant/components/device_tracker/legacy.py @@ -44,7 +44,11 @@ from homeassistant.helpers.event import ( ) from homeassistant.helpers.restore_state import RestoreEntity from homeassistant.helpers.typing import ConfigType, GPSType, StateType -from homeassistant.setup import async_prepare_setup_platform, async_start_setup +from homeassistant.setup import ( + async_notify_setup_error, + async_prepare_setup_platform, + async_start_setup, +) from homeassistant.util import dt as dt_util from homeassistant.util.yaml import dump @@ -1007,6 +1011,7 @@ async def async_load_config( device["dev_id"] = cv.slugify(dev_id) except vol.Invalid as exp: async_log_schema_error(exp, dev_id, devices, hass) + async_notify_setup_error(hass, DOMAIN) else: result.append(Device(hass, **device)) return result diff --git a/homeassistant/components/template/config.py b/homeassistant/components/template/config.py index d1198b46577..9da43082d2b 100644 --- a/homeassistant/components/template/config.py +++ b/homeassistant/components/template/config.py @@ -12,8 +12,11 @@ from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN from homeassistant.components.weather import DOMAIN as WEATHER_DOMAIN from homeassistant.config import async_log_schema_error, config_without_domain from homeassistant.const import CONF_BINARY_SENSORS, CONF_SENSORS, CONF_UNIQUE_ID +from homeassistant.core import HomeAssistant from homeassistant.helpers import config_validation as cv from homeassistant.helpers.trigger import async_validate_trigger_config +from homeassistant.helpers.typing import ConfigType +from homeassistant.setup import async_notify_setup_error from . import ( binary_sensor as binary_sensor_platform, @@ -64,7 +67,7 @@ CONFIG_SECTION_SCHEMA = vol.Schema( ) -async def async_validate_config(hass, config): +async def async_validate_config(hass: HomeAssistant, config: ConfigType) -> ConfigType: """Validate config.""" if DOMAIN not in config: return config @@ -81,6 +84,7 @@ async def async_validate_config(hass, config): ) except vol.Invalid as err: async_log_schema_error(err, DOMAIN, cfg, hass) + async_notify_setup_error(hass, DOMAIN) continue legacy_warn_printed = False diff --git a/homeassistant/config.py b/homeassistant/config.py index a9c505b0a68..fc806790bc9 100644 --- a/homeassistant/config.py +++ b/homeassistant/config.py @@ -68,7 +68,6 @@ from .helpers.entity_values import EntityValues from .helpers.typing import ConfigType from .loader import ComponentProtocol, Integration, IntegrationNotFound from .requirements import RequirementsNotFound, async_get_integration_with_requirements -from .setup import async_notify_setup_error from .util.package import is_docker_env from .util.unit_system import get_unit_system, validate_unit_system from .util.yaml import SECRET_YAML, Secrets, load_yaml @@ -549,8 +548,6 @@ def async_log_schema_error( link: str | None = None, ) -> None: """Log a schema validation error.""" - if hass is not None: - async_notify_setup_error(hass, domain, link) message = format_schema_error(hass, ex, domain, config, link) _LOGGER.error(message) @@ -568,8 +565,6 @@ def async_log_config_validator_error( async_log_schema_error(ex, domain, config, hass, link) return - if hass is not None: - async_notify_setup_error(hass, domain, link) message = format_homeassistant_error(hass, ex, domain, config, link) _LOGGER.error(message, exc_info=ex) diff --git a/tests/test_bootstrap.py b/tests/test_bootstrap.py index f6d3b92bb4a..b98d3d0311f 100644 --- a/tests/test_bootstrap.py +++ b/tests/test_bootstrap.py @@ -719,7 +719,7 @@ async def test_setup_hass_invalid_core_config( event_loop: asyncio.AbstractEventLoop, ) -> None: """Test it works.""" - with patch("homeassistant.config.async_notify_setup_error") as mock_notify: + with patch("homeassistant.bootstrap.async_notify_setup_error") as mock_notify: hass = await bootstrap.async_setup_hass( runner.RuntimeConfig( config_dir=get_test_config_dir(),