mirror of
https://github.com/home-assistant/core.git
synced 2025-12-25 05:26:47 +00:00
Split out storage delay save (#16017)
* Split out storage delayed write * Update code using delayed save * Fix tests * Fix typing test * Add callback decorator
This commit is contained in:
@@ -56,7 +56,7 @@ async def test_loading_parallel(hass, store, hass_storage, caplog):
|
||||
|
||||
async def test_saving_with_delay(hass, store, hass_storage):
|
||||
"""Test saving data after a delay."""
|
||||
await store.async_save(MOCK_DATA, delay=1)
|
||||
store.async_delay_save(lambda: MOCK_DATA, 1)
|
||||
assert store.key not in hass_storage
|
||||
|
||||
async_fire_time_changed(hass, dt.utcnow() + timedelta(seconds=1))
|
||||
@@ -71,7 +71,7 @@ async def test_saving_with_delay(hass, store, hass_storage):
|
||||
async def test_saving_on_stop(hass, hass_storage):
|
||||
"""Test delayed saves trigger when we quit Home Assistant."""
|
||||
store = storage.Store(hass, MOCK_VERSION, MOCK_KEY)
|
||||
await store.async_save(MOCK_DATA, delay=1)
|
||||
store.async_delay_save(lambda: MOCK_DATA, 1)
|
||||
assert store.key not in hass_storage
|
||||
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
||||
@@ -92,7 +92,7 @@ async def test_loading_while_delay(hass, store, hass_storage):
|
||||
'data': {'delay': 'no'},
|
||||
}
|
||||
|
||||
await store.async_save({'delay': 'yes'}, delay=1)
|
||||
store.async_delay_save(lambda: {'delay': 'yes'}, 1)
|
||||
assert hass_storage[store.key] == {
|
||||
'version': MOCK_VERSION,
|
||||
'key': MOCK_KEY,
|
||||
@@ -105,7 +105,7 @@ async def test_loading_while_delay(hass, store, hass_storage):
|
||||
|
||||
async def test_writing_while_writing_delay(hass, store, hass_storage):
|
||||
"""Test a write while a write with delay is active."""
|
||||
await store.async_save({'delay': 'yes'}, delay=1)
|
||||
store.async_delay_save(lambda: {'delay': 'yes'}, 1)
|
||||
assert store.key not in hass_storage
|
||||
await store.async_save({'delay': 'no'})
|
||||
assert hass_storage[store.key] == {
|
||||
|
||||
Reference in New Issue
Block a user