Made bootstrap.setup_component more robust
This commit is contained in:
1 parent
58812b326c
commit
2863c2d593
5 files changed
+44
-18
No files matched your search
@@ -31,18 +31,46 @@ ATTR_COMPONENT = "component"
|
||||
|
||||
|
||||
def setup_component(hass, domain, config=None):
|
||||
""" Setup a component for Home Assistant. """
|
||||
# Check if already loaded
|
||||
""" Setup a component and all its dependencies. """
|
||||
|
||||
if domain in hass.config.components:
|
||||
return
|
||||
return True
|
||||
|
||||
_ensure_loader_prepared(hass)
|
||||
|
||||
if config is None:
|
||||
config = defaultdict(dict)
|
||||
|
||||
components = loader.load_order_component(domain)
|
||||
|
||||
# OrderedSet is empty if component or dependencies could not be resolved
|
||||
if not components:
|
||||
return False
|
||||
|
||||
for component in components:
|
||||
if component in hass.config.components:
|
||||
continue
|
||||
|
||||
if not _setup_component(hass, component, config):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def _setup_component(hass, domain, config):
|
||||
""" Setup a component for Home Assistant. """
|
||||
component = loader.get_component(domain)
|
||||
|
||||
missing_deps = [dep for dep in component.DEPENDENCIES
|
||||
if dep not in hass.config.components]
|
||||
|
||||
if missing_deps:
|
||||
_LOGGER.error(
|
||||
"Not initializing %s because not all dependencies loaded: %s",
|
||||
domain, ", ".join(missing_deps))
|
||||
|
||||
return False
|
||||
|
||||
try:
|
||||
if component.setup(hass, config):
|
||||
hass.config.components.append(component.DOMAIN)
|
||||
@@ -102,7 +130,7 @@ def from_config_dict(config, hass=None):
|
||||
|
||||
# Setup the components
|
||||
for domain in loader.load_order_components(components):
|
||||
setup_component(hass, domain, config)
|
||||
_setup_component(hass, domain, config)
|
||||
|
||||
return hass
|
||||
|
||||
|
||||
Reference in new issue
Block a user