Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion homeassistant/components/esphome/entry_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

DATA_KEY = "esphome"

SAVE_DELAY = 120
Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Member Author

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.

Copy link
Copy Markdown
Member

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_wait to delay_save to make sure it's written eventually (besides on shutdown).


# Mapping from ESPHome info type to HA platform
INFO_TYPE_TO_PLATFORM = {
BinarySensorInfo: "binary_sensor",
Expand Down Expand Up @@ -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)
Copy link
Copy Markdown
Member

@balloob balloob Oct 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one.

We should find all the async_save and make them delays unless it's auth related (user/config entry).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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 .py files from disk.

self.store.async_delay_save(lambda: store_data, SAVE_DELAY)


def _attr_obj_from_dict(cls, **kwargs):
Expand Down