mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
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:
committed by
Paulus Schoutsen
parent
2b9fb73032
commit
fdc373f27e
@@ -1,5 +1,6 @@
|
||||
"""The tests for the logbook component."""
|
||||
# pylint: disable=protected-access
|
||||
# pylint: disable=protected-access,invalid-name
|
||||
import logging
|
||||
from datetime import timedelta
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
@@ -13,7 +14,11 @@ import homeassistant.util.dt as dt_util
|
||||
from homeassistant.components import logbook
|
||||
from homeassistant.bootstrap import setup_component
|
||||
|
||||
from tests.common import mock_http_component, get_test_home_assistant
|
||||
from tests.common import (
|
||||
mock_http_component, init_recorder_component, get_test_home_assistant)
|
||||
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TestComponentLogbook(unittest.TestCase):
|
||||
@@ -24,12 +29,14 @@ class TestComponentLogbook(unittest.TestCase):
|
||||
def setUp(self):
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
init_recorder_component(self.hass) # Force an in memory DB
|
||||
mock_http_component(self.hass)
|
||||
self.hass.config.components |= set(['frontend', 'recorder', 'api'])
|
||||
with patch('homeassistant.components.logbook.'
|
||||
'register_built_in_panel'):
|
||||
assert setup_component(self.hass, logbook.DOMAIN,
|
||||
self.EMPTY_CONFIG)
|
||||
self.hass.start()
|
||||
|
||||
def tearDown(self):
|
||||
"""Stop everything that was started."""
|
||||
@@ -41,6 +48,7 @@ class TestComponentLogbook(unittest.TestCase):
|
||||
|
||||
@ha.callback
|
||||
def event_listener(event):
|
||||
"""Append on event."""
|
||||
calls.append(event)
|
||||
|
||||
self.hass.bus.listen(logbook.EVENT_LOGBOOK_ENTRY, event_listener)
|
||||
@@ -72,6 +80,7 @@ class TestComponentLogbook(unittest.TestCase):
|
||||
|
||||
@ha.callback
|
||||
def event_listener(event):
|
||||
"""Append on event."""
|
||||
calls.append(event)
|
||||
|
||||
self.hass.bus.listen(logbook.EVENT_LOGBOOK_ENTRY, event_listener)
|
||||
@@ -242,17 +251,17 @@ class TestComponentLogbook(unittest.TestCase):
|
||||
entity_id2 = 'sensor.blu'
|
||||
|
||||
eventA = ha.Event(logbook.EVENT_LOGBOOK_ENTRY, {
|
||||
logbook.ATTR_NAME: name,
|
||||
logbook.ATTR_MESSAGE: message,
|
||||
logbook.ATTR_DOMAIN: domain,
|
||||
logbook.ATTR_ENTITY_ID: entity_id,
|
||||
})
|
||||
logbook.ATTR_NAME: name,
|
||||
logbook.ATTR_MESSAGE: message,
|
||||
logbook.ATTR_DOMAIN: domain,
|
||||
logbook.ATTR_ENTITY_ID: entity_id,
|
||||
})
|
||||
eventB = ha.Event(logbook.EVENT_LOGBOOK_ENTRY, {
|
||||
logbook.ATTR_NAME: name,
|
||||
logbook.ATTR_MESSAGE: message,
|
||||
logbook.ATTR_DOMAIN: domain,
|
||||
logbook.ATTR_ENTITY_ID: entity_id2,
|
||||
})
|
||||
logbook.ATTR_NAME: name,
|
||||
logbook.ATTR_MESSAGE: message,
|
||||
logbook.ATTR_DOMAIN: domain,
|
||||
logbook.ATTR_ENTITY_ID: entity_id2,
|
||||
})
|
||||
|
||||
config = logbook.CONFIG_SCHEMA({
|
||||
ha.DOMAIN: {},
|
||||
@@ -532,7 +541,8 @@ class TestComponentLogbook(unittest.TestCase):
|
||||
|
||||
def create_state_changed_event(self, event_time_fired, entity_id, state,
|
||||
attributes=None, last_changed=None,
|
||||
last_updated=None):
|
||||
last_updated=None): \
|
||||
# pylint: disable=no-self-use
|
||||
"""Create state changed event."""
|
||||
# Logbook only cares about state change events that
|
||||
# contain an old state but will not actually act on it.
|
||||
|
||||
Reference in New Issue
Block a user