Migrate check-config to use get_integration (#23026)
* Migrate check-config to use get_integration * ImportError
This commit is contained in:
parent
2c07bfb9e0
commit
f269135ae9
2 changed files with 24 additions and 6 deletions
|
@ -329,8 +329,16 @@ def check_ha_config_file(hass):
|
||||||
|
|
||||||
# Process and validate config
|
# Process and validate config
|
||||||
for domain in components:
|
for domain in components:
|
||||||
component = loader.get_component(hass, domain)
|
try:
|
||||||
if not component:
|
integration = hass.loop.run_until_complete(
|
||||||
|
loader.async_get_integration(hass, domain))
|
||||||
|
except loader.IntegrationNotFound:
|
||||||
|
result.add_error("Integration not found: {}".format(domain))
|
||||||
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
component = integration.get_component()
|
||||||
|
except ImportError:
|
||||||
result.add_error("Component not found: {}".format(domain))
|
result.add_error("Component not found: {}".format(domain))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -368,9 +376,18 @@ def check_ha_config_file(hass):
|
||||||
platforms.append(p_validated)
|
platforms.append(p_validated)
|
||||||
continue
|
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(
|
result.add_error(
|
||||||
"Platform not found: {}.{}".format(domain, p_name))
|
"Platform not found: {}.{}".format(domain, p_name))
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -90,7 +90,7 @@ class TestCheckConfig(unittest.TestCase):
|
||||||
res = check_config.check(get_test_config_dir())
|
res = check_config.check(get_test_config_dir())
|
||||||
assert res['components'].keys() == {'homeassistant'}
|
assert res['components'].keys() == {'homeassistant'}
|
||||||
assert res['except'] == {
|
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['secret_cache'] == {}
|
||||||
assert res['secrets'] == {}
|
assert res['secrets'] == {}
|
||||||
assert len(res['yaml_files']) == 1
|
assert len(res['yaml_files']) == 1
|
||||||
|
@ -104,7 +104,8 @@ class TestCheckConfig(unittest.TestCase):
|
||||||
assert res['components']['light'] == []
|
assert res['components']['light'] == []
|
||||||
assert res['except'] == {
|
assert res['except'] == {
|
||||||
check_config.ERROR_STR: [
|
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['secret_cache'] == {}
|
||||||
assert res['secrets'] == {}
|
assert res['secrets'] == {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue