mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Allow IntegrationNotFound when checking config in safe mode (#56283)
Co-authored-by: Joakim Sørensen <hi@ludeeus.dev>
This commit is contained in:
parent
bad6b2f7f5
commit
eb98ac9415
@ -125,8 +125,12 @@ async def async_check_ha_config_file( # noqa: C901
|
|||||||
for domain in components:
|
for domain in components:
|
||||||
try:
|
try:
|
||||||
integration = await async_get_integration_with_requirements(hass, domain)
|
integration = await async_get_integration_with_requirements(hass, domain)
|
||||||
except (RequirementsNotFound, loader.IntegrationNotFound) as ex:
|
except loader.IntegrationNotFound as ex:
|
||||||
result.add_error(f"Component error: {domain} - {ex}")
|
if not hass.config.safe_mode:
|
||||||
|
result.add_error(f"Integration error: {domain} - {ex}")
|
||||||
|
continue
|
||||||
|
except RequirementsNotFound as ex:
|
||||||
|
result.add_error(f"Integration error: {domain} - {ex}")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -210,8 +214,11 @@ async def async_check_ha_config_file( # noqa: C901
|
|||||||
hass, p_name
|
hass, p_name
|
||||||
)
|
)
|
||||||
platform = p_integration.get_platform(domain)
|
platform = p_integration.get_platform(domain)
|
||||||
|
except loader.IntegrationNotFound as ex:
|
||||||
|
if not hass.config.safe_mode:
|
||||||
|
result.add_error(f"Platform error {domain}.{p_name} - {ex}")
|
||||||
|
continue
|
||||||
except (
|
except (
|
||||||
loader.IntegrationNotFound,
|
|
||||||
RequirementsNotFound,
|
RequirementsNotFound,
|
||||||
ImportError,
|
ImportError,
|
||||||
) as ex:
|
) as ex:
|
||||||
|
@ -7,6 +7,7 @@ from homeassistant.helpers.check_config import (
|
|||||||
CheckConfigError,
|
CheckConfigError,
|
||||||
async_check_ha_config_file,
|
async_check_ha_config_file,
|
||||||
)
|
)
|
||||||
|
from homeassistant.requirements import RequirementsNotFound
|
||||||
|
|
||||||
from tests.common import mock_platform, patch_yaml_files
|
from tests.common import mock_platform, patch_yaml_files
|
||||||
|
|
||||||
@ -75,7 +76,7 @@ async def test_component_platform_not_found(hass):
|
|||||||
|
|
||||||
assert res.keys() == {"homeassistant"}
|
assert res.keys() == {"homeassistant"}
|
||||||
assert res.errors[0] == CheckConfigError(
|
assert res.errors[0] == CheckConfigError(
|
||||||
"Component error: beer - Integration 'beer' not found.", None, None
|
"Integration error: beer - Integration 'beer' not found.", None, None
|
||||||
)
|
)
|
||||||
|
|
||||||
# Only 1 error expected
|
# Only 1 error expected
|
||||||
@ -83,6 +84,42 @@ async def test_component_platform_not_found(hass):
|
|||||||
assert not res.errors
|
assert not res.errors
|
||||||
|
|
||||||
|
|
||||||
|
async def test_component_requirement_not_found(hass):
|
||||||
|
"""Test errors if component with a requirement not found not found."""
|
||||||
|
# Make sure they don't exist
|
||||||
|
files = {YAML_CONFIG_FILE: BASE_CONFIG + "test_custom_component:"}
|
||||||
|
with patch(
|
||||||
|
"homeassistant.helpers.check_config.async_get_integration_with_requirements",
|
||||||
|
side_effect=RequirementsNotFound("test_custom_component", ["any"]),
|
||||||
|
), patch("os.path.isfile", return_value=True), patch_yaml_files(files):
|
||||||
|
res = await async_check_ha_config_file(hass)
|
||||||
|
log_ha_config(res)
|
||||||
|
|
||||||
|
assert res.keys() == {"homeassistant"}
|
||||||
|
assert res.errors[0] == CheckConfigError(
|
||||||
|
"Integration error: test_custom_component - Requirements for test_custom_component not found: ['any'].",
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Only 1 error expected
|
||||||
|
res.errors.pop(0)
|
||||||
|
assert not res.errors
|
||||||
|
|
||||||
|
|
||||||
|
async def test_component_not_found_safe_mode(hass):
|
||||||
|
"""Test no errors if component not found in safe mode."""
|
||||||
|
# Make sure they don't exist
|
||||||
|
files = {YAML_CONFIG_FILE: BASE_CONFIG + "beer:"}
|
||||||
|
hass.config.safe_mode = True
|
||||||
|
with patch("os.path.isfile", return_value=True), patch_yaml_files(files):
|
||||||
|
res = await async_check_ha_config_file(hass)
|
||||||
|
log_ha_config(res)
|
||||||
|
|
||||||
|
assert res.keys() == {"homeassistant"}
|
||||||
|
assert not res.errors
|
||||||
|
|
||||||
|
|
||||||
async def test_component_platform_not_found_2(hass):
|
async def test_component_platform_not_found_2(hass):
|
||||||
"""Test errors if component or platform not found."""
|
"""Test errors if component or platform not found."""
|
||||||
# Make sure they don't exist
|
# Make sure they don't exist
|
||||||
@ -103,6 +140,21 @@ async def test_component_platform_not_found_2(hass):
|
|||||||
assert not res.errors
|
assert not res.errors
|
||||||
|
|
||||||
|
|
||||||
|
async def test_platform_not_found_safe_mode(hass):
|
||||||
|
"""Test no errors if platform not found in safe_mode."""
|
||||||
|
# Make sure they don't exist
|
||||||
|
files = {YAML_CONFIG_FILE: BASE_CONFIG + "light:\n platform: beer"}
|
||||||
|
hass.config.safe_mode = True
|
||||||
|
with patch("os.path.isfile", return_value=True), patch_yaml_files(files):
|
||||||
|
res = await async_check_ha_config_file(hass)
|
||||||
|
log_ha_config(res)
|
||||||
|
|
||||||
|
assert res.keys() == {"homeassistant", "light"}
|
||||||
|
assert res["light"] == []
|
||||||
|
|
||||||
|
assert not res.errors
|
||||||
|
|
||||||
|
|
||||||
async def test_package_invalid(hass):
|
async def test_package_invalid(hass):
|
||||||
"""Test a valid platform setup."""
|
"""Test a valid platform setup."""
|
||||||
files = {
|
files = {
|
||||||
|
@ -74,7 +74,7 @@ def test_component_platform_not_found(mock_is_file, loop):
|
|||||||
assert res["components"].keys() == {"homeassistant"}
|
assert res["components"].keys() == {"homeassistant"}
|
||||||
assert res["except"] == {
|
assert res["except"] == {
|
||||||
check_config.ERROR_STR: [
|
check_config.ERROR_STR: [
|
||||||
"Component error: beer - Integration 'beer' not found."
|
"Integration error: beer - Integration 'beer' not found."
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
assert res["secret_cache"] == {}
|
assert res["secret_cache"] == {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user