-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add storage helper and migrate config entries #15045
Conversation
To do: pass in version and migrate function to store constructor -> DONE |
homeassistant/helpers/storage.py
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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_job
if 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: