Check for import errors before validating config (#28395)
This commit is contained in:
parent
674860e00e
commit
70c4b4a4f0
2 changed files with 19 additions and 6 deletions
|
@ -132,6 +132,17 @@ async def _async_setup_component(
|
|||
log_error(str(err))
|
||||
return False
|
||||
|
||||
# Some integrations fail on import because they call functions incorrectly.
|
||||
# So we do it before validating config to catch these errors.
|
||||
try:
|
||||
component = integration.get_component()
|
||||
except ImportError:
|
||||
log_error("Unable to import component", False)
|
||||
return False
|
||||
except Exception: # pylint: disable=broad-except
|
||||
_LOGGER.exception("Setup failed for %s: unknown error", domain)
|
||||
return False
|
||||
|
||||
processed_config = await conf_util.async_process_component_config(
|
||||
hass, config, integration
|
||||
)
|
||||
|
@ -143,12 +154,6 @@ async def _async_setup_component(
|
|||
start = timer()
|
||||
_LOGGER.info("Setting up %s", domain)
|
||||
|
||||
try:
|
||||
component = integration.get_component()
|
||||
except ImportError:
|
||||
log_error("Unable to import component", False)
|
||||
return False
|
||||
|
||||
if hasattr(component, "PLATFORM_SCHEMA"):
|
||||
# Entity components have their own warning
|
||||
warn_task = None
|
||||
|
|
|
@ -527,3 +527,11 @@ async def test_when_setup_already_loaded(hass):
|
|||
setup.async_when_setup(hass, "test", mock_callback)
|
||||
await hass.async_block_till_done()
|
||||
assert calls == ["test", "test"]
|
||||
|
||||
|
||||
async def test_setup_import_blows_up(hass):
|
||||
"""Test that we handle it correctly when importing integration blows up."""
|
||||
with mock.patch(
|
||||
"homeassistant.loader.Integration.get_component", side_effect=ValueError
|
||||
):
|
||||
assert not await setup.async_setup_component(hass, "sun", {})
|
||||
|
|
Loading…
Add table
Reference in a new issue