hass-core/tests/components/test_input_boolean.py
Paulus Schoutsen 609d7ebea5 Migrate core from threads to async awesomeness (#3248)
* Add event loop to the core

* Add block_till_done to HA core object

* Fix some tests

* Linting core

* Fix statemachine tests

* Core test fixes

* fix block_till_done to wait for loop and queue to empty

* fix test_core for passing, and correct start/stop/block_till_done

* Fix remote tests

* Fix tests: block_till_done

* Fix linting

* Fix more tests

* Fix final linting

* Fix remote test

* remove unnecessary import

* reduce sleep to avoid slowing down the tests excessively

* fix remaining tests to wait for non-threadsafe operations

* Add async_ doc strings for event loop / coroutine info

* Fix command line test to block for the right timeout

* Fix py3.4.2 loop var access

* Fix SERVICE_CALL_LIMIT being in effect for other tests

* Fix lint errors

* Fix lint error with proper placement

* Fix slave start to not start a timer

* Add asyncio compatible listeners.

* Increase min Python version to 3.4.2

* Move async backports to util

* Add backported async tests

* Fix linting

* Simplify Python version check

* Fix lint

* Remove unneeded try/except and queue listener appproriately.

* Fix tuple vs. list unorderable error on version compare.

* Fix version tests
2016-09-12 19:16:14 -07:00

96 lines
2.9 KiB
Python

"""The tests for the input_boolean component."""
# pylint: disable=too-many-public-methods,protected-access
import unittest
from homeassistant.components import input_boolean
from homeassistant.const import (
STATE_ON, STATE_OFF, ATTR_ICON, ATTR_FRIENDLY_NAME)
from tests.common import get_test_home_assistant
class TestInputBoolean(unittest.TestCase):
"""Test the input boolean module."""
def setUp(self): # pylint: disable=invalid-name
"""Setup things to be run when tests are started."""
self.hass = get_test_home_assistant()
def tearDown(self): # pylint: disable=invalid-name
"""Stop everything that was started."""
self.hass.stop()
def test_config(self):
"""Test config."""
self.assertFalse(input_boolean.setup(self.hass, {
'input_boolean': None
}))
self.assertFalse(input_boolean.setup(self.hass, {
'input_boolean': {
}
}))
self.assertFalse(input_boolean.setup(self.hass, {
'input_boolean': {
'name with space': None
}
}))
def test_methods(self):
"""Test is_on, turn_on, turn_off methods."""
self.assertTrue(input_boolean.setup(self.hass, {
'input_boolean': {
'test_1': None,
}
}))
entity_id = 'input_boolean.test_1'
self.assertFalse(
input_boolean.is_on(self.hass, entity_id))
input_boolean.turn_on(self.hass, entity_id)
self.hass.block_till_done()
self.assertTrue(
input_boolean.is_on(self.hass, entity_id))
input_boolean.turn_off(self.hass, entity_id)
self.hass.block_till_done()
self.assertFalse(
input_boolean.is_on(self.hass, entity_id))
def test_config_options(self):
"""Test configuration options."""
count_start = len(self.hass.states.entity_ids())
self.assertTrue(input_boolean.setup(self.hass, {
'input_boolean': {
'test_1': None,
'test_2': {
'name': 'Hello World',
'icon': 'work',
'initial': True,
},
},
}))
self.assertEqual(count_start + 2, len(self.hass.states.entity_ids()))
state_1 = self.hass.states.get('input_boolean.test_1')
state_2 = self.hass.states.get('input_boolean.test_2')
self.assertIsNotNone(state_1)
self.assertIsNotNone(state_2)
self.assertEqual(STATE_OFF, state_1.state)
self.assertNotIn(ATTR_ICON, state_1.attributes)
self.assertNotIn(ATTR_FRIENDLY_NAME, state_1.attributes)
self.assertEqual(STATE_ON, state_2.state)
self.assertEqual('Hello World',
state_2.attributes.get(ATTR_FRIENDLY_NAME))
self.assertEqual('work', state_2.attributes.get(ATTR_ICON))