Add script logic into helper.
This commit is contained in:
@@ -34,13 +34,6 @@ class TestScript(unittest.TestCase):
|
||||
'sequence': [{'event': 'bla'}]
|
||||
}
|
||||
},
|
||||
{
|
||||
'test': {
|
||||
'sequence': {
|
||||
'event': 'test_event'
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
'test': {
|
||||
'sequence': {
|
||||
@@ -49,7 +42,6 @@ class TestScript(unittest.TestCase):
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
):
|
||||
assert not _setup_component(self.hass, 'script', {
|
||||
'script': value
|
||||
@@ -206,45 +198,6 @@ class TestScript(unittest.TestCase):
|
||||
|
||||
self.assertEqual(2, len(calls))
|
||||
|
||||
def test_alt_delay(self):
|
||||
"""Test alternative delay config format."""
|
||||
event = 'test_event'
|
||||
calls = []
|
||||
|
||||
def record_event(event):
|
||||
"""Add recorded event to set."""
|
||||
calls.append(event)
|
||||
|
||||
self.hass.bus.listen(event, record_event)
|
||||
|
||||
assert _setup_component(self.hass, 'script', {
|
||||
'script': {
|
||||
'test': {
|
||||
'sequence': [{
|
||||
'event': event,
|
||||
}, {
|
||||
'delay': None,
|
||||
'seconds': 5
|
||||
}, {
|
||||
'event': event,
|
||||
}]
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
script.turn_on(self.hass, ENTITY_ID)
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
self.assertTrue(script.is_on(self.hass, ENTITY_ID))
|
||||
self.assertEqual(1, len(calls))
|
||||
|
||||
future = dt_util.utcnow() + timedelta(seconds=5)
|
||||
fire_time_changed(self.hass, future)
|
||||
self.hass.pool.block_till_done()
|
||||
|
||||
self.assertFalse(script.is_on(self.hass, ENTITY_ID))
|
||||
self.assertEqual(2, len(calls))
|
||||
|
||||
def test_cancel_while_delay(self):
|
||||
"""Test the cancelling while the delay is present."""
|
||||
event = 'test_event'
|
||||
|
||||
@@ -145,18 +145,19 @@ def test_icon():
|
||||
schema('mdi:work')
|
||||
|
||||
|
||||
def test_time_offset():
|
||||
"""Test time_offset validation."""
|
||||
schema = vol.Schema(cv.time_offset)
|
||||
def test_time_period():
|
||||
"""Test time_period validation."""
|
||||
schema = vol.Schema(cv.time_period)
|
||||
|
||||
for value in (
|
||||
None, '', 1234, 'hello:world', '12:', '12:34:56:78'
|
||||
None, '', 1234, 'hello:world', '12:', '12:34:56:78',
|
||||
{}, {'wrong_key': -10}
|
||||
):
|
||||
with pytest.raises(vol.MultipleInvalid):
|
||||
schema(value)
|
||||
|
||||
for value in (
|
||||
'8:20', '23:59', '-8:20', '-23:59:59', '-48:00'
|
||||
'8:20', '23:59', '-8:20', '-23:59:59', '-48:00', {'minutes': 5}
|
||||
):
|
||||
schema(value)
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ class TestServiceHelpers(unittest.TestCase):
|
||||
self.assertEqual(1, len(runs))
|
||||
|
||||
def test_template_service_call(self):
|
||||
""" Test service call with tempating. """
|
||||
"""Test service call with tempating."""
|
||||
config = {
|
||||
'service_template': '{{ \'test_domain.test_service\' }}',
|
||||
'entity_id': 'hello.world',
|
||||
@@ -56,6 +56,7 @@ class TestServiceHelpers(unittest.TestCase):
|
||||
self.assertEqual('goodbye', runs[0].data['hello'])
|
||||
|
||||
def test_passing_variables_to_templates(self):
|
||||
"""Test passing variables to templates."""
|
||||
config = {
|
||||
'service_template': '{{ var_service }}',
|
||||
'entity_id': 'hello.world',
|
||||
@@ -141,7 +142,7 @@ class TestServiceHelpers(unittest.TestCase):
|
||||
service.extract_entity_ids(self.hass, call))
|
||||
|
||||
def test_validate_service_call(self):
|
||||
"""Test is_valid_service_call method"""
|
||||
"""Test is_valid_service_call method."""
|
||||
self.assertNotEqual(
|
||||
service.validate_service_call(
|
||||
{}),
|
||||
|
||||
Reference in New Issue
Block a user