diff --git a/homeassistant/helpers/storage.py b/homeassistant/helpers/storage.py index 087f98e4c42..03b66843819 100644 --- a/homeassistant/helpers/storage.py +++ b/homeassistant/helpers/storage.py @@ -15,6 +15,7 @@ from homeassistant.const import EVENT_HOMEASSISTANT_FINAL_WRITE from homeassistant.core import CALLBACK_TYPE, CoreState, Event, HomeAssistant, callback from homeassistant.loader import MAX_LOAD_CONCURRENTLY, bind_hass from homeassistant.util import json as json_util +from homeassistant.util.file import WriteError # mypy: allow-untyped-calls, allow-untyped-defs, no-warn-return-any # mypy: no-check-untyped-defs @@ -278,7 +279,7 @@ class Store(Generic[_T]): try: await self._async_write_data(self.path, data) - except (json_util.SerializationError, json_util.WriteError) as err: + except (json_util.SerializationError, WriteError) as err: _LOGGER.error("Error writing config for %s: %s", self.key, err) async def _async_write_data(self, path: str, data: dict) -> None: diff --git a/homeassistant/util/json.py b/homeassistant/util/json.py index a31db4f8d1b..c1ced053930 100644 --- a/homeassistant/util/json.py +++ b/homeassistant/util/json.py @@ -16,7 +16,11 @@ from homeassistant.helpers.json import ( json_encoder_default as default_hass_orjson_encoder, ) -from .file import write_utf8_file, write_utf8_file_atomic +from .file import ( # pylint: disable=unused-import # noqa: F401 + WriteError, + write_utf8_file, + write_utf8_file_atomic, +) _LOGGER = logging.getLogger(__name__) @@ -25,10 +29,6 @@ class SerializationError(HomeAssistantError): """Error serializing the data to JSON.""" -class WriteError(HomeAssistantError): - """Error writing the data.""" - - def load_json(filename: str, default: list | dict | None = None) -> list | dict: """Load JSON data from a file and return as dict or list.