1
mirror of https://github.com/home-assistant/core synced 2024-07-30 21:18:57 +02:00

Make setup more robust (#23414)

* Make setup more robust

* Fix typing
This commit is contained in:
Paulus Schoutsen 2019-04-26 12:41:30 -07:00 committed by Pascal Vizeli
parent 61ea6256c6
commit d6f6273ac2

View File

@ -151,9 +151,12 @@ async def _async_setup_component(hass: core.HomeAssistant,
if hasattr(component, 'async_setup'): if hasattr(component, 'async_setup'):
result = await component.async_setup( # type: ignore result = await component.async_setup( # type: ignore
hass, processed_config) hass, processed_config)
else: elif hasattr(component, 'setup'):
result = await hass.async_add_executor_job( result = await hass.async_add_executor_job(
component.setup, hass, processed_config) # type: ignore component.setup, hass, processed_config) # type: ignore
else:
log_error("No setup function defined.")
return False
except Exception: # pylint: disable=broad-except except Exception: # pylint: disable=broad-except
_LOGGER.exception("Error during setup of component %s", domain) _LOGGER.exception("Error during setup of component %s", domain)
async_notify_setup_error(hass, domain, True) async_notify_setup_error(hass, domain, True)
@ -176,7 +179,7 @@ async def _async_setup_component(hass: core.HomeAssistant,
for entry in hass.config_entries.async_entries(domain): for entry in hass.config_entries.async_entries(domain):
await entry.async_setup(hass, integration=integration) await entry.async_setup(hass, integration=integration)
hass.config.components.add(component.DOMAIN) # type: ignore hass.config.components.add(domain)
# Cleanup # Cleanup
if domain in hass.data[DATA_SETUP]: if domain in hass.data[DATA_SETUP]:
@ -184,7 +187,7 @@ async def _async_setup_component(hass: core.HomeAssistant,
hass.bus.async_fire( hass.bus.async_fire(
EVENT_COMPONENT_LOADED, EVENT_COMPONENT_LOADED,
{ATTR_COMPONENT: component.DOMAIN} # type: ignore {ATTR_COMPONENT: domain}
) )
return True return True