1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Allow platforms to specify dependencies

This commit is contained in:
Paulus Schoutsen
2015-05-11 22:23:20 -07:00
parent d7ab76106d
commit e630476f9f
2 changed files with 40 additions and 7 deletions

View File

@@ -30,6 +30,8 @@ _LOGGER = logging.getLogger(__name__)
ATTR_COMPONENT = "component"
PLATFORM_FORMAT = '{}.{}'
def setup_component(hass, domain, config=None):
""" Setup a component and all its dependencies. """
@@ -95,6 +97,35 @@ def _setup_component(hass, domain, config):
return False
def prepare_setup_platform(hass, config, domain, platform_name):
""" Loads a platform and makes sure dependencies are setup. """
_ensure_loader_prepared(hass)
platform_path = PLATFORM_FORMAT.format(domain, platform_name)
platform = loader.get_component(platform_path)
# Not found
if platform is None:
_LOGGER.error('Unable to find platform %s', platform_path)
return None
# Already loaded or no dependencies
elif (platform_path in hass.config.components or
not hasattr(platform, 'DEPENDENCIES')):
return platform
# Load dependencies
for component in platform.DEPENDENCIES:
if not setup_component(hass, component, config):
_LOGGER.error(
'Unable to prepare setup for platform %s because not all '
'dependencies could be initialized', platform_path)
return None
return platform
# pylint: disable=too-many-branches, too-many-statements
def from_config_dict(config, hass=None):
"""