Warn if config invalid shape for script

This commit is contained in:
Paulus Schoutsen 2015-11-26 13:08:13 -08:00
parent d4f0f0ffd3
commit 2861bbb02c
2 changed files with 17 additions and 16 deletions

View File

@ -76,8 +76,9 @@ def setup(hass, config):
_LOGGER.warn("Found invalid key for script: %s. Use %s instead.",
object_id, slugify(object_id))
continue
if not cfg.get(CONF_SEQUENCE):
_LOGGER.warn("Missing key 'sequence' for script %s", object_id)
if not isinstance(cfg.get(CONF_SEQUENCE), list):
_LOGGER.warn("Key 'sequence' for script %s should be a list",
object_id)
continue
alias = cfg.get(CONF_ALIAS, object_id)
script = Script(hass, object_id, alias, cfg[CONF_SEQUENCE])

View File

@ -27,23 +27,10 @@ class TestScript(unittest.TestCase):
""" Stop down stuff we started. """
self.hass.stop()
def test_setup_with_empty_sequence(self):
self.assertTrue(script.setup(self.hass, {
'script': {
'test': {
'sequence': []
}
}
}))
self.assertIsNone(self.hass.states.get(ENTITY_ID))
def test_setup_with_missing_sequence(self):
self.assertTrue(script.setup(self.hass, {
'script': {
'test': {
'sequence': []
}
'test': {}
}
}))
@ -60,6 +47,19 @@ class TestScript(unittest.TestCase):
self.assertEqual(0, len(self.hass.states.entity_ids('script')))
def test_setup_with_dict_as_sequence(self):
self.assertTrue(script.setup(self.hass, {
'script': {
'test': {
'sequence': {
'event': 'test_event'
}
}
}
}))
self.assertEqual(0, len(self.hass.states.entity_ids('script')))
def test_firing_event(self):
event = 'test_event'
calls = []