Make integration setup optional (#48381)

This commit is contained in:
Franck Nijhof
2021-03-29 22:53:47 +02:00
committed by GitHub
parent dda9f957b6
commit 52475c108f
16 changed files with 39 additions and 77 deletions

View File

@@ -169,7 +169,7 @@ async def _async_setup_component(
return False
if integration.disabled:
log_error(f"dependency is disabled - {integration.disabled}")
log_error(f"Dependency is disabled - {integration.disabled}")
return False
# Validate all dependencies exist and there are no circular dependencies
@@ -219,6 +219,8 @@ async def _async_setup_component(
SLOW_SETUP_WARNING,
)
task = None
result = True
try:
if hasattr(component, "async_setup"):
task = component.async_setup(hass, processed_config) # type: ignore
@@ -228,13 +230,14 @@ async def _async_setup_component(
task = hass.loop.run_in_executor(
None, component.setup, hass, processed_config # type: ignore
)
else:
log_error("No setup function defined.")
elif not hasattr(component, "async_setup_entry"):
log_error("No setup or config entry setup function defined.")
hass.data[DATA_SETUP_STARTED].pop(domain)
return False
async with hass.timeout.async_timeout(SLOW_SETUP_MAX_WAIT, domain):
result = await task
if task:
async with hass.timeout.async_timeout(SLOW_SETUP_MAX_WAIT, domain):
result = await task
except asyncio.TimeoutError:
_LOGGER.error(
"Setup of %s is taking longer than %s seconds."