From d6f6273ac2c76e6eb1b3609623b9e1a2c163cfb0 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 26 Apr 2019 12:41:30 -0700 Subject: [PATCH] Make setup more robust (#23414) * Make setup more robust * Fix typing --- homeassistant/setup.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/homeassistant/setup.py b/homeassistant/setup.py index 05e3307299a..ee362ad130f 100644 --- a/homeassistant/setup.py +++ b/homeassistant/setup.py @@ -151,9 +151,12 @@ async def _async_setup_component(hass: core.HomeAssistant, if hasattr(component, 'async_setup'): result = await component.async_setup( # type: ignore hass, processed_config) - else: + elif hasattr(component, 'setup'): result = await hass.async_add_executor_job( component.setup, hass, processed_config) # type: ignore + else: + log_error("No setup function defined.") + return False except Exception: # pylint: disable=broad-except _LOGGER.exception("Error during setup of component %s", domain) 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): await entry.async_setup(hass, integration=integration) - hass.config.components.add(component.DOMAIN) # type: ignore + hass.config.components.add(domain) # Cleanup if domain in hass.data[DATA_SETUP]: @@ -184,7 +187,7 @@ async def _async_setup_component(hass: core.HomeAssistant, hass.bus.async_fire( EVENT_COMPONENT_LOADED, - {ATTR_COMPONENT: component.DOMAIN} # type: ignore + {ATTR_COMPONENT: domain} ) return True