Defer esphome persistent storage writes until after startup (#42600)
Avoid disk I/O during startup as it can cause delays when a user has many esphome devices.
This commit is contained in:
parent
2bbd2a6e70
commit
8a403cde00
1 changed files with 3 additions and 1 deletions
|
@ -31,6 +31,8 @@ if TYPE_CHECKING:
|
||||||
|
|
||||||
DATA_KEY = "esphome"
|
DATA_KEY = "esphome"
|
||||||
|
|
||||||
|
SAVE_DELAY = 120
|
||||||
|
|
||||||
# Mapping from ESPHome info type to HA platform
|
# Mapping from ESPHome info type to HA platform
|
||||||
INFO_TYPE_TO_PLATFORM = {
|
INFO_TYPE_TO_PLATFORM = {
|
||||||
BinarySensorInfo: "binary_sensor",
|
BinarySensorInfo: "binary_sensor",
|
||||||
|
@ -159,7 +161,7 @@ class RuntimeEntryData:
|
||||||
for service in self.services.values():
|
for service in self.services.values():
|
||||||
store_data["services"].append(service.to_dict())
|
store_data["services"].append(service.to_dict())
|
||||||
|
|
||||||
await self.store.async_save(store_data)
|
self.store.async_delay_save(lambda: store_data, SAVE_DELAY)
|
||||||
|
|
||||||
|
|
||||||
def _attr_obj_from_dict(cls, **kwargs):
|
def _attr_obj_from_dict(cls, **kwargs):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue