Protect loop set default executor (#37438)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Paulus Schoutsen 2020-07-06 15:58:53 -07:00 committed by GitHub
parent f8651d9faa
commit f49ce5d1b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 387 additions and 244 deletions

View file

@ -1,5 +1,6 @@
"""Script to check the configuration file."""
import argparse
import asyncio
from collections import OrderedDict
from collections.abc import Mapping, Sequence
from glob import glob
@ -199,12 +200,7 @@ def check(config_dir, secrets=False):
yaml_loader.yaml.SafeLoader.add_constructor("!secret", yaml_loader.secret_yaml)
try:
hass = core.HomeAssistant()
hass.config.config_dir = config_dir
res["components"] = hass.loop.run_until_complete(
async_check_ha_config_file(hass)
)
res["components"] = asyncio.run(async_check_config(config_dir))
res["secret_cache"] = OrderedDict(yaml_loader.__SECRET_CACHE)
for err in res["components"].errors:
domain = err.domain or ERROR_STR
@ -213,7 +209,6 @@ def check(config_dir, secrets=False):
res["except"].setdefault(domain, []).append(err.config)
except Exception as err: # pylint: disable=broad-except
_LOGGER.exception("BURB")
print(color("red", "Fatal error while loading config:"), str(err))
res["except"].setdefault(ERROR_STR, []).append(str(err))
finally:
@ -230,6 +225,15 @@ def check(config_dir, secrets=False):
return res
async def async_check_config(config_dir):
"""Check the HA config."""
hass = core.HomeAssistant()
hass.config.config_dir = config_dir
components = await async_check_ha_config_file(hass)
await hass.async_stop(force=True)
return components
def line_info(obj, **kwargs):
"""Display line config source."""
if hasattr(obj, "__config_file__"):