Skip to content

Commit

Permalink
Migrate check-config to use get_integration
Browse files Browse the repository at this point in the history
  • Loading branch information
balloob committed Apr 11, 2019
1 parent 7e39e14 commit b5c71c8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
24 changes: 20 additions & 4 deletions homeassistant/scripts/check_config.py
Expand Up @@ -17,7 +17,7 @@
CONF_PACKAGES, merge_packages_config, _format_config_error,
find_config_file, load_yaml_config_file,
extract_domain_configs, config_per_platform)
from homeassistant.util import yaml
from homeassistant.util import yaml, async_
from homeassistant.exceptions import HomeAssistantError

REQUIREMENTS = ('colorlog==4.0.2',)
Expand Down Expand Up @@ -329,7 +329,14 @@ def _comp_error(ex, domain, config):

# Process and validate config
for domain in components:
component = loader.get_component(hass, domain)
try:
integration = hass.loop.run_until_complete(
loader.async_get_integration(hass, domain))
except loader.IntegrationNotFound:
result.add_error("Integration not found: {}".format(domain))
continue

component = integration.get_component()
if not component:
result.add_error("Component not found: {}".format(domain))
continue
Expand Down Expand Up @@ -368,9 +375,18 @@ def _comp_error(ex, domain, config):
platforms.append(p_validated)
continue

platform = loader.get_platform(hass, domain, p_name)
try:
p_integration = hass.loop.run_until_complete(
loader.async_get_integration(hass, p_name))
except loader.IntegrationNotFound:
result.add_error(
"Integration {} not found when trying to verify its {} "
"platform.".format(p_name, domain))
continue

if platform is None:
try:
platform = p_integration.get_platform(domain)
except ImportError:
result.add_error(
"Platform not found: {}.{}".format(domain, p_name))
continue
Expand Down
5 changes: 3 additions & 2 deletions tests/scripts/test_check_config.py
Expand Up @@ -90,7 +90,7 @@ def test_component_platform_not_found(self, isfile_patch):
res = check_config.check(get_test_config_dir())
assert res['components'].keys() == {'homeassistant'}
assert res['except'] == {
check_config.ERROR_STR: ['Component not found: beer']}
check_config.ERROR_STR: ['Integration not found: beer']}
assert res['secret_cache'] == {}
assert res['secrets'] == {}
assert len(res['yaml_files']) == 1
Expand All @@ -104,7 +104,8 @@ def test_component_platform_not_found(self, isfile_patch):
assert res['components']['light'] == []
assert res['except'] == {
check_config.ERROR_STR: [
'Platform not found: light.beer',
'Integration beer not found when trying to verify its '
'light platform.',
]}
assert res['secret_cache'] == {}
assert res['secrets'] == {}
Expand Down

0 comments on commit b5c71c8

Please sign in to comment.