2015-08-11 05:21:34 +00:00
|
|
|
"""
|
|
|
|
tests.test_component_demo
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Tests demo component.
|
|
|
|
"""
|
|
|
|
import unittest
|
|
|
|
|
2015-08-17 03:44:46 +00:00
|
|
|
import homeassistant.core as ha
|
2015-08-11 05:21:34 +00:00
|
|
|
import homeassistant.loader as loader
|
|
|
|
import homeassistant.util.dt as dt_util
|
|
|
|
import homeassistant.components.automation as automation
|
|
|
|
import homeassistant.components.automation.time as time
|
|
|
|
from homeassistant.const import CONF_PLATFORM
|
|
|
|
|
|
|
|
from tests.common import fire_time_changed
|
|
|
|
|
|
|
|
|
|
|
|
class TestAutomationTime(unittest.TestCase):
|
|
|
|
""" Test the event automation. """
|
|
|
|
|
|
|
|
def setUp(self): # pylint: disable=invalid-name
|
|
|
|
self.hass = ha.HomeAssistant()
|
|
|
|
self.calls = []
|
|
|
|
|
|
|
|
def record_call(service):
|
|
|
|
self.calls.append(service)
|
|
|
|
|
|
|
|
self.hass.services.register('test', 'automation', record_call)
|
|
|
|
|
|
|
|
def tearDown(self): # pylint: disable=invalid-name
|
|
|
|
""" Stop down stuff we started. """
|
|
|
|
self.hass.stop()
|
|
|
|
|
|
|
|
def test_if_fires_when_hour_matches(self):
|
2015-08-11 06:11:46 +00:00
|
|
|
self.assertTrue(automation.setup(self.hass, {
|
2015-08-11 05:21:34 +00:00
|
|
|
automation.DOMAIN: {
|
|
|
|
CONF_PLATFORM: 'time',
|
|
|
|
time.CONF_HOURS: 0,
|
|
|
|
automation.CONF_SERVICE: 'test.automation'
|
|
|
|
}
|
2015-08-11 06:11:46 +00:00
|
|
|
}))
|
2015-08-11 05:21:34 +00:00
|
|
|
|
|
|
|
fire_time_changed(self.hass, dt_util.utcnow().replace(hour=0))
|
|
|
|
|
|
|
|
self.hass.states.set('test.entity', 'world')
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
self.assertEqual(1, len(self.calls))
|
|
|
|
|
|
|
|
def test_if_fires_when_minute_matches(self):
|
2015-08-11 06:11:46 +00:00
|
|
|
self.assertTrue(automation.setup(self.hass, {
|
2015-08-11 05:21:34 +00:00
|
|
|
automation.DOMAIN: {
|
|
|
|
CONF_PLATFORM: 'time',
|
|
|
|
time.CONF_MINUTES: 0,
|
|
|
|
automation.CONF_SERVICE: 'test.automation'
|
|
|
|
}
|
2015-08-11 06:11:46 +00:00
|
|
|
}))
|
2015-08-11 05:21:34 +00:00
|
|
|
|
|
|
|
fire_time_changed(self.hass, dt_util.utcnow().replace(minute=0))
|
|
|
|
|
|
|
|
self.hass.states.set('test.entity', 'world')
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
self.assertEqual(1, len(self.calls))
|
|
|
|
|
|
|
|
def test_if_fires_when_second_matches(self):
|
2015-08-11 06:11:46 +00:00
|
|
|
self.assertTrue(automation.setup(self.hass, {
|
2015-08-11 05:21:34 +00:00
|
|
|
automation.DOMAIN: {
|
|
|
|
CONF_PLATFORM: 'time',
|
|
|
|
time.CONF_SECONDS: 0,
|
|
|
|
automation.CONF_SERVICE: 'test.automation'
|
|
|
|
}
|
2015-08-11 06:11:46 +00:00
|
|
|
}))
|
2015-08-11 05:21:34 +00:00
|
|
|
|
|
|
|
fire_time_changed(self.hass, dt_util.utcnow().replace(second=0))
|
|
|
|
|
|
|
|
self.hass.states.set('test.entity', 'world')
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
self.assertEqual(1, len(self.calls))
|
|
|
|
|
|
|
|
def test_if_fires_when_all_matches(self):
|
2015-08-11 06:11:46 +00:00
|
|
|
self.assertTrue(automation.setup(self.hass, {
|
2015-08-11 05:21:34 +00:00
|
|
|
automation.DOMAIN: {
|
|
|
|
CONF_PLATFORM: 'time',
|
|
|
|
time.CONF_HOURS: 0,
|
|
|
|
time.CONF_MINUTES: 0,
|
|
|
|
time.CONF_SECONDS: 0,
|
|
|
|
automation.CONF_SERVICE: 'test.automation'
|
|
|
|
}
|
2015-08-11 06:11:46 +00:00
|
|
|
}))
|
2015-08-11 05:21:34 +00:00
|
|
|
|
|
|
|
fire_time_changed(self.hass, dt_util.utcnow().replace(
|
|
|
|
hour=0, minute=0, second=0))
|
|
|
|
|
|
|
|
self.hass.states.set('test.entity', 'world')
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
self.assertEqual(1, len(self.calls))
|