mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
check_config script evolution (#12792)
* Initial async_check_ha_config_file * check_ha_config_file * Various fixes * feedback - return the config * move_to_check_config
This commit is contained in:
committed by
Paulus Schoutsen
parent
5e2296f2a4
commit
6734c966b3
@@ -41,9 +41,9 @@ VERSION_FILE = '.HA_VERSION'
|
||||
CONFIG_DIR_NAME = '.homeassistant'
|
||||
DATA_CUSTOMIZE = 'hass_customize'
|
||||
|
||||
FILE_MIGRATION = [
|
||||
['ios.conf', '.ios.conf'],
|
||||
]
|
||||
FILE_MIGRATION = (
|
||||
('ios.conf', '.ios.conf'),
|
||||
)
|
||||
|
||||
DEFAULT_CORE_CONFIG = (
|
||||
# Tuples (attribute, default, auto detect property, description)
|
||||
@@ -304,6 +304,9 @@ def load_yaml_config_file(config_path):
|
||||
_LOGGER.error(msg)
|
||||
raise HomeAssistantError(msg)
|
||||
|
||||
# Convert values to dictionaries if they are None
|
||||
for key, value in conf_dict.items():
|
||||
conf_dict[key] = value or {}
|
||||
return conf_dict
|
||||
|
||||
|
||||
@@ -345,14 +348,22 @@ def process_ha_config_upgrade(hass):
|
||||
|
||||
@callback
|
||||
def async_log_exception(ex, domain, config, hass):
|
||||
"""Log an error for configuration validation.
|
||||
|
||||
This method must be run in the event loop.
|
||||
"""
|
||||
if hass is not None:
|
||||
async_notify_setup_error(hass, domain, True)
|
||||
_LOGGER.error(_format_config_error(ex, domain, config))
|
||||
|
||||
|
||||
@callback
|
||||
def _format_config_error(ex, domain, config):
|
||||
"""Generate log exception for configuration validation.
|
||||
|
||||
This method must be run in the event loop.
|
||||
"""
|
||||
message = "Invalid config for [{}]: ".format(domain)
|
||||
if hass is not None:
|
||||
async_notify_setup_error(hass, domain, True)
|
||||
|
||||
if 'extra keys not allowed' in ex.error_message:
|
||||
message += '[{}] is an invalid option for [{}]. Check: {}->{}.'\
|
||||
.format(ex.path[-1], domain, domain,
|
||||
@@ -369,7 +380,7 @@ def async_log_exception(ex, domain, config, hass):
|
||||
message += ('Please check the docs at '
|
||||
'https://home-assistant.io/components/{}/'.format(domain))
|
||||
|
||||
_LOGGER.error(message)
|
||||
return message
|
||||
|
||||
|
||||
async def async_process_ha_core_config(hass, config):
|
||||
@@ -497,7 +508,7 @@ async def async_process_ha_core_config(hass, config):
|
||||
|
||||
|
||||
def _log_pkg_error(package, component, config, message):
|
||||
"""Log an error while merging."""
|
||||
"""Log an error while merging packages."""
|
||||
message = "Package {} setup failed. Component {} {}".format(
|
||||
package, component, message)
|
||||
|
||||
@@ -523,7 +534,7 @@ def _identify_config_schema(module):
|
||||
return '', schema
|
||||
|
||||
|
||||
def merge_packages_config(config, packages):
|
||||
def merge_packages_config(config, packages, _log_pkg_error=_log_pkg_error):
|
||||
"""Merge packages into the top-level configuration. Mutate config."""
|
||||
# pylint: disable=too-many-nested-blocks
|
||||
PACKAGES_CONFIG_SCHEMA(packages)
|
||||
@@ -589,7 +600,7 @@ def merge_packages_config(config, packages):
|
||||
def async_process_component_config(hass, config, domain):
|
||||
"""Check component configuration and return processed configuration.
|
||||
|
||||
Raise a vol.Invalid exception on error.
|
||||
Returns None on error.
|
||||
|
||||
This method must be run in the event loop.
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user