1
0
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:
Paulus Schoutsen
2018-08-17 20:18:21 +02:00
committed by GitHub
parent fdbab3e20c
commit 2ad0bd4036
4 changed files with 65 additions and 38 deletions

View File

@@ -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] == {