mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Check for import errors before validating config (#28395)
This commit is contained in:
parent
674860e00e
commit
70c4b4a4f0
@ -132,6 +132,17 @@ async def _async_setup_component(
|
|||||||
log_error(str(err))
|
log_error(str(err))
|
||||||
return False
|
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(
|
processed_config = await conf_util.async_process_component_config(
|
||||||
hass, config, integration
|
hass, config, integration
|
||||||
)
|
)
|
||||||
@ -143,12 +154,6 @@ async def _async_setup_component(
|
|||||||
start = timer()
|
start = timer()
|
||||||
_LOGGER.info("Setting up %s", domain)
|
_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"):
|
if hasattr(component, "PLATFORM_SCHEMA"):
|
||||||
# Entity components have their own warning
|
# Entity components have their own warning
|
||||||
warn_task = None
|
warn_task = None
|
||||||
|
@ -527,3 +527,11 @@ async def test_when_setup_already_loaded(hass):
|
|||||||
setup.async_when_setup(hass, "test", mock_callback)
|
setup.async_when_setup(hass, "test", mock_callback)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert calls == ["test", "test"]
|
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…
x
Reference in New Issue
Block a user