Fix handling with reset/default on json (#1669)

* Fix handling with reset/default on json

* black
This commit is contained in:
Pascal Vizeli 2020-04-22 11:06:49 +02:00 committed by GitHub
parent 06fa9f9a9e
commit ffa91e150d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,6 +11,8 @@ from ..exceptions import JsonFileError
_LOGGER: logging.Logger = logging.getLogger(__name__)
_DEFAULT: Dict[str, Any] = {}
def write_json_file(jsonfile: Path, data: Any) -> None:
"""Write a JSON file."""
@ -37,7 +39,7 @@ class JsonConfig:
"""Initialize hass object."""
self._file: Path = json_file
self._schema: vol.Schema = schema
self._data: Dict[str, Any] = {}
self._data: Dict[str, Any] = _DEFAULT
self.read_data()
@ -68,7 +70,7 @@ class JsonConfig:
# Reset data to default
_LOGGER.warning("Reset %s to default", self._file)
self._data = self._schema({})
self._data = self._schema(_DEFAULT)
def save_data(self) -> None:
"""Store data to configuration file."""
@ -80,6 +82,7 @@ class JsonConfig:
# Load last valid data
_LOGGER.warning("Reset %s to last version", self._file)
self._data = _DEFAULT
self.read_data()
else:
# write