Add persistent notification

This commit is contained in:
Otto Winter 2019-02-15 18:40:46 +01:00
parent f6ae054e9f
commit 06f2aa93a4
No known key found for this signature in database
GPG Key ID: DB66C0BE6013F97E
2 changed files with 28 additions and 9 deletions

View File

@ -192,6 +192,23 @@ async def async_from_config_dict(config: Dict[str, Any],
'\n\n'.join(msg), "Config Warning", "config_warning" '\n\n'.join(msg), "Config Warning", "config_warning"
) )
# TEMP: warn users for invalid slugs
# Remove after 0.92
if cv.INVALID_EXTRA_KEYS_FOUND:
msg = []
msg.append(
"Your configuration contains extra keys "
"that the platform does not support (but were silently "
"accepted before 0.88). Please find and remove the following."
"This will become a breaking change."
)
msg.append('\n'.join('- {}'.format(it)
for it in cv.INVALID_EXTRA_KEYS_FOUND))
hass.components.persistent_notification.async_create(
'\n\n'.join(msg), "Config Warning", "config_warning"
)
return hass return hass

View File

@ -25,8 +25,6 @@ from homeassistant.helpers import template as template_helper
from homeassistant.helpers.logging import KeywordStyleAdapter from homeassistant.helpers.logging import KeywordStyleAdapter
from homeassistant.util import slugify as util_slugify from homeassistant.util import slugify as util_slugify
_LOGGER = logging.getLogger(__name__)
# pylint: disable=invalid-name # pylint: disable=invalid-name
TIME_PERIOD_ERROR = "offset {} should be format 'HH:MM' or 'HH:MM:SS'" TIME_PERIOD_ERROR = "offset {} should be format 'HH:MM' or 'HH:MM:SS'"
@ -36,6 +34,7 @@ OLD_ENTITY_ID_VALIDATION = r"^(\w+)\.(\w+)$"
# persistent notification. Rare temporary exception to use a global. # persistent notification. Rare temporary exception to use a global.
INVALID_SLUGS_FOUND = {} INVALID_SLUGS_FOUND = {}
INVALID_ENTITY_IDS_FOUND = {} INVALID_ENTITY_IDS_FOUND = {}
INVALID_EXTRA_KEYS_FOUND = []
# Home Assistant types # Home Assistant types
@ -661,14 +660,17 @@ class HASchema(vol.Schema):
if err.error_message == 'extra keys not allowed'] if err.error_message == 'extra keys not allowed']
if extra_key_errs: if extra_key_errs:
msg = "Your configuration contains extra keys " \ msg = "Your configuration contains extra keys " \
"that the platform does not support. The keys " "that the platform does not support.\n" \
msg += ', '.join('[{}]'.format(err.path[-1]) for err in "Please remove "
extra_key_errs) submsg = ', '.join('[{}]'.format(err.path[-1]) for err in
msg += ' are 42.' extra_key_errs)
submsg += '. '
if hasattr(data, '__config_file__'): if hasattr(data, '__config_file__'):
msg += " (See {}, line {}). ".format(data.__config_file__, submsg += " (See {}, line {}). ".format(
data.__line__) data.__config_file__, data.__line__)
_LOGGER.warning(msg) msg += submsg
logging.getLogger(__name__).warning(msg)
INVALID_EXTRA_KEYS_FOUND.append(submsg)
else: else:
# This should not happen (all errors should be extra key # This should not happen (all errors should be extra key
# errors). Let's raise the original error anyway. # errors). Let's raise the original error anyway.