Restore_state helper to restore entity states from the DB on startup (#4614)

* Restore states

* feedback

* Remove component move into recorder

* space

* helper

* Address my own comments

* Improve test coverage

* Add test for light restore state
This commit is contained in:
Johann Kellerman 2017-02-21 09:40:27 +02:00 committed by Paulus Schoutsen
parent 2b9fb73032
commit fdc373f27e
18 changed files with 425 additions and 184 deletions

View file

@ -1,16 +1,17 @@
"""The test for the History Statistics sensor platform."""
# pylint: disable=protected-access
import unittest
from datetime import timedelta
import unittest
from unittest.mock import patch
import homeassistant.components.recorder as recorder
import homeassistant.core as ha
import homeassistant.util.dt as dt_util
from homeassistant.bootstrap import setup_component
import homeassistant.components.recorder as recorder
from homeassistant.components.sensor.history_stats import HistoryStatsSensor
import homeassistant.core as ha
from homeassistant.helpers.template import Template
from tests.common import get_test_home_assistant
import homeassistant.util.dt as dt_util
from tests.common import init_recorder_component, get_test_home_assistant
class TestHistoryStatsSensor(unittest.TestCase):
@ -204,12 +205,8 @@ class TestHistoryStatsSensor(unittest.TestCase):
def init_recorder(self):
"""Initialize the recorder."""
db_uri = 'sqlite://'
with patch('homeassistant.core.Config.path', return_value=db_uri):
setup_component(self.hass, recorder.DOMAIN, {
"recorder": {
"db_url": db_uri}})
init_recorder_component(self.hass)
self.hass.start()
recorder._INSTANCE.block_till_db_ready()
recorder.get_instance().block_till_db_ready()
self.hass.block_till_done()
recorder._INSTANCE.block_till_done()
recorder.get_instance().block_till_done()