-
-
Notifications
You must be signed in to change notification settings - Fork 37.4k
Defer esphome persistent storage writes until after startup #42600
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,8 @@ | |
|
|
||
| DATA_KEY = "esphome" | ||
|
|
||
| SAVE_DELAY = 120 | ||
|
|
||
| # Mapping from ESPHome info type to HA platform | ||
| INFO_TYPE_TO_PLATFORM = { | ||
| BinarySensorInfo: "binary_sensor", | ||
|
|
@@ -159,7 +161,7 @@ async def async_save_to_store(self) -> None: | |
| for service in self.services.values(): | ||
| store_data["services"].append(service.to_dict()) | ||
|
|
||
| await self.store.async_save(store_data) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice one. We should find all the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll audit what else is done at startup and adjust since these are the ones we except to be I/O bound since they are competing with loading the |
||
| self.store.async_delay_save(lambda: store_data, SAVE_DELAY) | ||
|
|
||
|
|
||
| def _attr_obj_from_dict(cls, **kwargs): | ||
|
|
||
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.
Is this going to be okay? If there never will be 2 minutes of no data, it will never save until HA is shut down.
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.
Should be fine since it only needs the data to re-setup the config entries with the last state before its able to make the connection to the device.
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 other use cases, we could consider adding a
max_waittodelay_saveto make sure it's written eventually (besides on shutdown).