Add input_text component (#9112)
This commit is contained in:
parent
9ede0f57e6
commit
552abf7da5
2 changed files with 349 additions and 0 deletions
147
tests/components/test_input_text.py
Executable file
147
tests/components/test_input_text.py
Executable file
|
@ -0,0 +1,147 @@
|
|||
"""The tests for the Input text component."""
|
||||
# pylint: disable=protected-access
|
||||
import asyncio
|
||||
import unittest
|
||||
|
||||
from homeassistant.core import CoreState, State
|
||||
from homeassistant.setup import setup_component, async_setup_component
|
||||
from homeassistant.components.input_text import (DOMAIN, select_value)
|
||||
|
||||
from tests.common import get_test_home_assistant, mock_restore_cache
|
||||
|
||||
|
||||
class TestInputText(unittest.TestCase):
|
||||
"""Test the input slider component."""
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def tearDown(self):
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
def test_config(self):
|
||||
"""Test config."""
|
||||
invalid_configs = [
|
||||
None,
|
||||
{},
|
||||
{'name with space': None},
|
||||
{'test_1': {
|
||||
'min': 50,
|
||||
'max': 50,
|
||||
}},
|
||||
]
|
||||
for cfg in invalid_configs:
|
||||
self.assertFalse(
|
||||
setup_component(self.hass, DOMAIN, {DOMAIN: cfg}))
|
||||
|
||||
def test_select_value(self):
|
||||
"""Test select_value method."""
|
||||
self.assertTrue(setup_component(self.hass, DOMAIN, {DOMAIN: {
|
||||
'test_1': {
|
||||
'initial': 'test',
|
||||
'min': 3,
|
||||
'max': 10,
|
||||
},
|
||||
}}))
|
||||
entity_id = 'input_text.test_1'
|
||||
|
||||
state = self.hass.states.get(entity_id)
|
||||
self.assertEqual('test', str(state.state))
|
||||
|
||||
select_value(self.hass, entity_id, 'testing')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get(entity_id)
|
||||
self.assertEqual('testing', str(state.state))
|
||||
|
||||
select_value(self.hass, entity_id, 'testing too long')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get(entity_id)
|
||||
self.assertEqual('testing', str(state.state))
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_restore_state(hass):
|
||||
"""Ensure states are restored on startup."""
|
||||
mock_restore_cache(hass, (
|
||||
State('input_text.b1', 'test'),
|
||||
State('input_text.b2', 'testing too long'),
|
||||
))
|
||||
|
||||
hass.state = CoreState.starting
|
||||
|
||||
yield from async_setup_component(hass, DOMAIN, {
|
||||
DOMAIN: {
|
||||
'b1': {
|
||||
'min': 0,
|
||||
'max': 10,
|
||||
},
|
||||
'b2': {
|
||||
'min': 0,
|
||||
'max': 10,
|
||||
},
|
||||
}})
|
||||
|
||||
state = hass.states.get('input_text.b1')
|
||||
assert state
|
||||
assert str(state.state) == 'test'
|
||||
|
||||
state = hass.states.get('input_text.b2')
|
||||
assert state
|
||||
assert str(state.state) == 'unknown'
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_initial_state_overrules_restore_state(hass):
|
||||
"""Ensure states are restored on startup."""
|
||||
mock_restore_cache(hass, (
|
||||
State('input_text.b1', 'testing'),
|
||||
State('input_text.b2', 'testing too long'),
|
||||
))
|
||||
|
||||
hass.state = CoreState.starting
|
||||
|
||||
yield from async_setup_component(hass, DOMAIN, {
|
||||
DOMAIN: {
|
||||
'b1': {
|
||||
'initial': 'test',
|
||||
'min': 0,
|
||||
'max': 10,
|
||||
},
|
||||
'b2': {
|
||||
'initial': 'test',
|
||||
'min': 0,
|
||||
'max': 10,
|
||||
},
|
||||
}})
|
||||
|
||||
state = hass.states.get('input_text.b1')
|
||||
assert state
|
||||
assert str(state.state) == 'test'
|
||||
|
||||
state = hass.states.get('input_text.b2')
|
||||
assert state
|
||||
assert str(state.state) == 'test'
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_no_initial_state_and_no_restore_state(hass):
|
||||
"""Ensure that entity is create without initial and restore feature."""
|
||||
hass.state = CoreState.starting
|
||||
|
||||
yield from async_setup_component(hass, DOMAIN, {
|
||||
DOMAIN: {
|
||||
'b1': {
|
||||
'min': 0,
|
||||
'max': 100,
|
||||
},
|
||||
}})
|
||||
|
||||
state = hass.states.get('input_text.b1')
|
||||
assert state
|
||||
assert str(state.state) == 'unknown'
|
Loading…
Add table
Add a link
Reference in a new issue