Migrate restore_state helper to use registry loading pattern (#93773)

* Migrate restore_state helper to use registry loading pattern

As more entities have started using restore_state over time, it
has become a startup bottleneck as each entity being added is
creating a task to load restore state data that is already loaded
since it is a singleton

We now use the same pattern as the registry helpers

* fix refactoring error -- guess I am tired

* fixes

* fix tests

* fix more

* fix more

* fix zha tests

* fix zha tests

* comments

* fix error

* add missing coverage

* s/DATA_RESTORE_STATE_TASK/DATA_RESTORE_STATE/g
This commit is contained in:
J. Nick Koston 2023-05-30 20:48:17 -05:00 committed by GitHub
parent b91c6911d9
commit fba826ae9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 147 additions and 86 deletions

View file

@ -34,7 +34,10 @@ from homeassistant.helpers.restore_state import STORAGE_KEY as RESTORE_STATE_KEY
from homeassistant.setup import async_setup_component
from homeassistant.util.unit_system import METRIC_SYSTEM, US_CUSTOMARY_SYSTEM
from tests.common import mock_restore_cache_with_extra_data
from tests.common import (
async_mock_restore_state_shutdown_restart,
mock_restore_cache_with_extra_data,
)
class MockDefaultNumberEntity(NumberEntity):
@ -635,7 +638,7 @@ async def test_restore_number_save_state(
await hass.async_block_till_done()
# Trigger saving state
await hass.async_stop()
await async_mock_restore_state_shutdown_restart(hass)
assert len(hass_storage[RESTORE_STATE_KEY]["data"]) == 1
state = hass_storage[RESTORE_STATE_KEY]["data"][0]["state"]