Skip to content

Commit

Permalink
Async timer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
emlove committed Nov 24, 2018
1 parent d24ea7d commit 1667230
Showing 1 changed file with 43 additions and 56 deletions.
99 changes: 43 additions & 56 deletions tests/components/timer/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from datetime import timedelta

from homeassistant.core import CoreState
from homeassistant.setup import setup_component, async_setup_component
from homeassistant.setup import async_setup_component
from homeassistant.components.timer import (
DOMAIN, CONF_DURATION, CONF_NAME, STATUS_ACTIVE, STATUS_IDLE,
STATUS_PAUSED, CONF_ICON, ATTR_DURATION, EVENT_TIMER_FINISHED,
Expand All @@ -20,69 +20,56 @@
_LOGGER = logging.getLogger(__name__)


class TestTimer(unittest.TestCase):
"""Test the timer component."""

# pylint: disable=invalid-name
def setUp(self):
"""Set up 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,
1,
{},
{'name with space': None},
]

for cfg in invalid_configs:
assert not setup_component(self.hass, DOMAIN, {DOMAIN: cfg})

def test_config_options(self):
"""Test configuration options."""
count_start = len(self.hass.states.entity_ids())

_LOGGER.debug('ENTITIES @ start: %s', self.hass.states.entity_ids())

config = {
DOMAIN: {
'test_1': {},
'test_2': {
CONF_NAME: 'Hello World',
CONF_ICON: 'mdi:work',
CONF_DURATION: 10,
}
async def test_config(hass):
"""Test config."""
invalid_configs = [
None,
1,
{},
{'name with space': None},
]

for cfg in invalid_configs:
assert not await async_setup_component(hass, DOMAIN, {DOMAIN: cfg})

async def test_config_options(hass):
"""Test configuration options."""
count_start = len(hass.states.async_entity_ids())

_LOGGER.debug('ENTITIES @ start: %s', hass.states.async_entity_ids())

config = {
DOMAIN: {
'test_1': {},
'test_2': {
CONF_NAME: 'Hello World',
CONF_ICON: 'mdi:work',
CONF_DURATION: 10,
}
}
}

assert setup_component(self.hass, 'timer', config)
self.hass.block_till_done()
assert await async_setup_component(hass, 'timer', config)
await hass.async_block_till_done()

assert count_start + 2 == len(self.hass.states.entity_ids())
self.hass.block_till_done()
assert count_start + 2 == len(hass.states.async_entity_ids())
await hass.async_block_till_done()

state_1 = self.hass.states.get('timer.test_1')
state_2 = self.hass.states.get('timer.test_2')
state_1 = hass.states.get('timer.test_1')
state_2 = hass.states.get('timer.test_2')

assert state_1 is not None
assert state_2 is not None
assert state_1 is not None
assert state_2 is not None

assert STATUS_IDLE == state_1.state
assert ATTR_ICON not in state_1.attributes
assert ATTR_FRIENDLY_NAME not in state_1.attributes
assert STATUS_IDLE == state_1.state
assert ATTR_ICON not in state_1.attributes
assert ATTR_FRIENDLY_NAME not in state_1.attributes

assert STATUS_IDLE == state_2.state
assert 'Hello World' == \
state_2.attributes.get(ATTR_FRIENDLY_NAME)
assert 'mdi:work' == state_2.attributes.get(ATTR_ICON)
assert '0:00:10' == state_2.attributes.get(ATTR_DURATION)
assert STATUS_IDLE == state_2.state
assert 'Hello World' == \
state_2.attributes.get(ATTR_FRIENDLY_NAME)
assert 'mdi:work' == state_2.attributes.get(ATTR_ICON)
assert '0:00:10' == state_2.attributes.get(ATTR_DURATION)


@asyncio.coroutine
Expand Down

0 comments on commit 1667230

Please sign in to comment.