From 9053341581f6674bc1d7cd214ac47abbcb8ff0c8 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Fri, 18 Jan 2019 18:57:54 +0100 Subject: [PATCH] Fix wrong UTF-8 config files (#895) * Fix wrong UTF-8 config files * Fix lint * Update data.py --- hassio/addons/data.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/hassio/addons/data.py b/hassio/addons/data.py index 86ad63cce..d28a85e5d 100644 --- a/hassio/addons/data.py +++ b/hassio/addons/data.py @@ -99,24 +99,27 @@ class AddonsData(JsonConfig, CoreSysAttributes): try: addon_config = read_json_file(addon) - # validate - addon_config = SCHEMA_ADDON_CONFIG(addon_config) - - # Generate slug - addon_slug = "{}_{}".format( - repository, addon_config[ATTR_SLUG]) - - # store - addon_config[ATTR_REPOSITORY] = repository - addon_config[ATTR_LOCATON] = str(addon.parent) - self._cache[addon_slug] = addon_config - - except (OSError, json.JSONDecodeError): + except (OSError, json.JSONDecodeError, UnicodeDecodeError): _LOGGER.warning("Can't read %s", addon) + continue + + # validate + try: + addon_config = SCHEMA_ADDON_CONFIG(addon_config) except vol.Invalid as ex: _LOGGER.warning("Can't read %s: %s", addon, humanize_error(addon_config, ex)) + continue + + # Generate slug + addon_slug = "{}_{}".format( + repository, addon_config[ATTR_SLUG]) + + # store + addon_config[ATTR_REPOSITORY] = repository + addon_config[ATTR_LOCATON] = str(addon.parent) + self._cache[addon_slug] = addon_config def _set_builtin_repositories(self): """Add local built-in repository into dataset."""