-
-
Notifications
You must be signed in to change notification settings - Fork 28.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add persistent notifications to bootstrap #3738
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,8 @@ | |
ATTR_COMPONENT = 'component' | ||
|
||
ERROR_LOG_FILENAME = 'home-assistant.log' | ||
_PERSISTENT_PLATFORMS = set() | ||
_PERSISTENT_VALIDATION = set() | ||
|
||
|
||
def setup_component(hass: core.HomeAssistant, domain: str, | ||
|
@@ -149,7 +151,7 @@ def prepare_setup_component(hass: core.HomeAssistant, config: dict, | |
try: | ||
config = component.CONFIG_SCHEMA(config) | ||
except vol.Invalid as ex: | ||
log_exception(ex, domain, config) | ||
log_exception(ex, domain, config, hass) | ||
return None | ||
|
||
elif hasattr(component, 'PLATFORM_SCHEMA'): | ||
|
@@ -159,7 +161,7 @@ def prepare_setup_component(hass: core.HomeAssistant, config: dict, | |
try: | ||
p_validated = component.PLATFORM_SCHEMA(p_config) | ||
except vol.Invalid as ex: | ||
log_exception(ex, domain, config) | ||
log_exception(ex, domain, config, hass) | ||
continue | ||
|
||
# Not all platform components follow same pattern for platforms | ||
|
@@ -181,7 +183,7 @@ def prepare_setup_component(hass: core.HomeAssistant, config: dict, | |
p_validated = platform.PLATFORM_SCHEMA(p_validated) | ||
except vol.Invalid as ex: | ||
log_exception(ex, '{}.{}'.format(domain, p_name), | ||
p_validated) | ||
p_validated, hass) | ||
continue | ||
|
||
platforms.append(p_validated) | ||
|
@@ -211,6 +213,13 @@ def prepare_setup_platform(hass: core.HomeAssistant, config, domain: str, | |
# Not found | ||
if platform is None: | ||
_LOGGER.error('Unable to find platform %s', platform_path) | ||
|
||
_PERSISTENT_PLATFORMS.add(platform_path) | ||
message = ('Unable to find the following platforms: ' + | ||
', '.join(list(_PERSISTENT_PLATFORMS)) + | ||
'(please check your configuration)') | ||
persistent_notification.create( | ||
hass, message, 'Invalid platforms', 'platform_errors') | ||
return None | ||
|
||
# Already loaded | ||
|
@@ -257,7 +266,7 @@ def from_config_dict(config: Dict[str, Any], | |
try: | ||
conf_util.process_ha_core_config(hass, core_config) | ||
except vol.Invalid as ex: | ||
log_exception(ex, 'homeassistant', core_config) | ||
log_exception(ex, 'homeassistant', core_config, hass) | ||
return None | ||
|
||
conf_util.process_ha_config_upgrade(hass) | ||
|
@@ -305,6 +314,7 @@ def component_setup(): | |
hass.loop.run_until_complete( | ||
hass.loop.run_in_executor(None, component_setup) | ||
) | ||
|
||
return hass | ||
|
||
|
||
|
@@ -397,9 +407,16 @@ def _ensure_loader_prepared(hass: core.HomeAssistant) -> None: | |
loader.prepare(hass) | ||
|
||
|
||
def log_exception(ex, domain, config): | ||
def log_exception(ex, domain, config, hass=None): | ||
"""Generate log exception for config validation.""" | ||
message = 'Invalid config for [{}]: '.format(domain) | ||
if hass is not None: | ||
_PERSISTENT_VALIDATION.add(domain) | ||
message = ('The following platforms contain invalid configuration: ' + | ||
', '.join(list(_PERSISTENT_VALIDATION)) + | ||
' (please check your configuration)') | ||
persistent_notification.create( | ||
hass, message, 'Invalid config', 'invalid_config') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By passing in an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of adding many cards with one error each, the messages lists them. There will be 2 type of messages: Invalid platformsUnable to find the following platforms: sensor.forecast, sensor.loch_ness_monster (please check your configuration) Invalid configThe following |
||
|
||
if 'extra keys not allowed' in ex.error_message: | ||
message += '[{}] is an invalid option for [{}]. Check: {}->{}.'\ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By passing in an
id
you will overwrite the previous message with that id.