mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 06:37:52 +00:00
Async timer tests (#18683)
This commit is contained in:
parent
50a30d4dc9
commit
66f1643de5
@ -1,12 +1,11 @@
|
|||||||
"""The tests for the timer component."""
|
"""The tests for the timer component."""
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
import asyncio
|
import asyncio
|
||||||
import unittest
|
|
||||||
import logging
|
import logging
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from homeassistant.core import CoreState
|
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 (
|
from homeassistant.components.timer import (
|
||||||
DOMAIN, CONF_DURATION, CONF_NAME, STATUS_ACTIVE, STATUS_IDLE,
|
DOMAIN, CONF_DURATION, CONF_NAME, STATUS_ACTIVE, STATUS_IDLE,
|
||||||
STATUS_PAUSED, CONF_ICON, ATTR_DURATION, EVENT_TIMER_FINISHED,
|
STATUS_PAUSED, CONF_ICON, ATTR_DURATION, EVENT_TIMER_FINISHED,
|
||||||
@ -15,25 +14,12 @@ from homeassistant.components.timer import (
|
|||||||
from homeassistant.const import (ATTR_ICON, ATTR_FRIENDLY_NAME, CONF_ENTITY_ID)
|
from homeassistant.const import (ATTR_ICON, ATTR_FRIENDLY_NAME, CONF_ENTITY_ID)
|
||||||
from homeassistant.util.dt import utcnow
|
from homeassistant.util.dt import utcnow
|
||||||
|
|
||||||
from tests.common import (get_test_home_assistant, async_fire_time_changed)
|
from tests.common import async_fire_time_changed
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class TestTimer(unittest.TestCase):
|
async def test_config(hass):
|
||||||
"""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."""
|
"""Test config."""
|
||||||
invalid_configs = [
|
invalid_configs = [
|
||||||
None,
|
None,
|
||||||
@ -43,13 +29,14 @@ class TestTimer(unittest.TestCase):
|
|||||||
]
|
]
|
||||||
|
|
||||||
for cfg in invalid_configs:
|
for cfg in invalid_configs:
|
||||||
assert not setup_component(self.hass, DOMAIN, {DOMAIN: cfg})
|
assert not await async_setup_component(hass, DOMAIN, {DOMAIN: cfg})
|
||||||
|
|
||||||
def test_config_options(self):
|
|
||||||
|
async def test_config_options(hass):
|
||||||
"""Test configuration options."""
|
"""Test configuration options."""
|
||||||
count_start = len(self.hass.states.entity_ids())
|
count_start = len(hass.states.async_entity_ids())
|
||||||
|
|
||||||
_LOGGER.debug('ENTITIES @ start: %s', self.hass.states.entity_ids())
|
_LOGGER.debug('ENTITIES @ start: %s', hass.states.async_entity_ids())
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
DOMAIN: {
|
DOMAIN: {
|
||||||
@ -62,14 +49,14 @@ class TestTimer(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert setup_component(self.hass, 'timer', config)
|
assert await async_setup_component(hass, 'timer', config)
|
||||||
self.hass.block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert count_start + 2 == len(self.hass.states.entity_ids())
|
assert count_start + 2 == len(hass.states.async_entity_ids())
|
||||||
self.hass.block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state_1 = self.hass.states.get('timer.test_1')
|
state_1 = hass.states.get('timer.test_1')
|
||||||
state_2 = self.hass.states.get('timer.test_2')
|
state_2 = hass.states.get('timer.test_2')
|
||||||
|
|
||||||
assert state_1 is not None
|
assert state_1 is not None
|
||||||
assert state_2 is not None
|
assert state_2 is not None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user