Restore states through a JSON store instead of recorder (#17270)

* Restore states through a JSON store

* Accept entity_id directly in restore state helper

* Keep states stored between runs for a limited time

* Remove warning
This commit is contained in:
Adam Mills 2018-11-28 07:16:43 -05:00 committed by Paulus Schoutsen
parent a039c3209b
commit 5c3a4e3d10
46 changed files with 493 additions and 422 deletions

View file

@ -1,7 +1,8 @@
"""Tests for the storage helper."""
import asyncio
from datetime import timedelta
from unittest.mock import patch
import json
from unittest.mock import patch, Mock
import pytest
@ -31,6 +32,21 @@ async def test_loading(hass, store):
assert data == MOCK_DATA
async def test_custom_encoder(hass):
"""Test we can save and load data."""
class JSONEncoder(json.JSONEncoder):
"""Mock JSON encoder."""
def default(self, o):
"""Mock JSON encode method."""
return "9"
store = storage.Store(hass, MOCK_VERSION, MOCK_KEY, encoder=JSONEncoder)
await store.async_save(Mock())
data = await store.async_load()
assert data == "9"
async def test_loading_non_existing(hass, store):
"""Test we can save and load data."""
with patch('homeassistant.util.json.open', side_effect=FileNotFoundError):