Add storage helper and migrate config entries#15045
Conversation
|
To do: pass in version and migrate function to store constructor -> DONE |
| except json.SerializationError as err: | ||
| _LOGGER.error('Error writing config for %s: %s', self.key, err) | ||
| except json.WriteError as err: | ||
| _LOGGER.error('Error writing config for %s: %s', self.key, err) |
There was a problem hiding this comment.
we should take that toggether like:
except (json.xy, json.ser) as err:
homeassistant/helpers/storage.py
Outdated
| self._async_cleanup_delay_listener() | ||
| await self._handle_write_data() | ||
|
|
||
| async def _handle_write_data(self, *_args): |
There was a problem hiding this comment.
you use for all async function async. That is the only function they use a other name concept
|
Future: It would be nice to add a voluptuous schema for data partition. That make it easy to add defaults or changes over the schema. |
|
I don't want to include voluptuous, the idea is that this is written/read by code, not humans. If defaults change, they can do a one time migration to create those. It should not run on every run. |
pvizeli
left a comment
There was a problem hiding this comment.
For simplify the code, I suggest to register the STOP event once and if they is reach, we can check if data are available and write it down or do nothing. So we need only handle the delay listener and can cleanup a lot of logic and code.
|
I don't want to register the STOP event during initialization because it means that startup of Home Assistant is slower. With the current logic, although it looks a bit complicated, we make sure that we only register handlers when we need it and and as little as possible. |
* Revert "Fix #14919. Should throw exception when camera stream closed by frontend (#15028)" This reverts commit 508d045. * Revert "Fix pylintrc section order and option placements (#15120)" This reverts commit dbae410. * Revert "Add storage helper and migrate config entries (#15045)" This reverts commit ae51dc0. * Revert "Add language to dark sky weather component (#15130)" This reverts commit 672a3c7.
* Add storage helper * Migrate config entries to use the storage helper * Make sure tests do not do I/O * Lint * Add versions to stored data * Add more instance variables * Make migrator load config if nothing to migrate * Address comments
…5142) * Revert "Fix home-assistant#14919. Should throw exception when camera stream closed by frontend (home-assistant#15028)" This reverts commit 508d045. * Revert "Fix pylintrc section order and option placements (home-assistant#15120)" This reverts commit dbae410. * Revert "Add storage helper and migrate config entries (home-assistant#15045)" This reverts commit ae51dc0. * Revert "Add language to dark sky weather component (home-assistant#15130)" This reverts commit 672a3c7.
* Add storage helper * Migrate config entries to use the storage helper * Make sure tests do not do I/O * Lint * Add versions to stored data * Add more instance variables * Make migrator load config if nothing to migrate * Address comments
…5142) * Revert "Fix home-assistant#14919. Should throw exception when camera stream closed by frontend (home-assistant#15028)" This reverts commit 508d045. * Revert "Fix pylintrc section order and option placements (home-assistant#15120)" This reverts commit dbae410. * Revert "Add storage helper and migrate config entries (home-assistant#15045)" This reverts commit ae51dc0. * Revert "Add language to dark sky weather component (home-assistant#15130)" This reverts commit 672a3c7.
Description:
This adds a storage helper. This will make it easier for components and core pieces to store and load data.
Since I did not want to add logic that is unused, I've migrated the config entries logic to use the new storage helper.
Bonus:
hass.async_add_executor_jobif we know it's going to be a sync method. This will be the new preferred way for sync methods. Will help step towards Make typing checks more strict #14429 (comment)Checklist:
tox. Your PR cannot be merged unless tests passIf the code does not interact with devices: