Restore for input_slider (#6360)

This commit is contained in:
Pascal Vizeli 2017-03-02 17:36:26 +01:00 committed by Paulus Schoutsen
parent a5b2fc9759
commit 08f9793175
2 changed files with 52 additions and 2 deletions

View file

@ -1,11 +1,14 @@
"""The tests for the Input slider component."""
# pylint: disable=protected-access
import asyncio
import unittest
from tests.common import get_test_home_assistant
from tests.common import get_test_home_assistant, mock_component
from homeassistant.bootstrap import setup_component
from homeassistant.core import CoreState, State
from homeassistant.bootstrap import setup_component, async_setup_component
from homeassistant.components.input_slider import (DOMAIN, select_value)
from homeassistant.helpers.restore_state import DATA_RESTORE_CACHE
class TestInputSlider(unittest.TestCase):
@ -67,3 +70,37 @@ class TestInputSlider(unittest.TestCase):
state = self.hass.states.get(entity_id)
self.assertEqual(70, float(state.state))
@asyncio.coroutine
def test_restore_state(hass):
"""Ensure states are restored on startup."""
hass.data[DATA_RESTORE_CACHE] = {
'input_slider.b1': State('input_slider.b1', '70'),
'input_slider.b2': State('input_slider.b2', '200'),
}
hass.state = CoreState.starting
mock_component(hass, 'recorder')
yield from async_setup_component(hass, DOMAIN, {
DOMAIN: {
'b1': {
'initial': 50,
'min': 0,
'max': 100,
},
'b2': {
'initial': 60,
'min': 0,
'max': 100,
},
}})
state = hass.states.get('input_slider.b1')
assert state
assert float(state.state) == 70
state = hass.states.get('input_slider.b2')
assert state
assert float(state.state) == 60