Automation - state platfor: Flag if user makes config error

This commit is contained in:
Paulus Schoutsen 2015-10-11 18:30:25 -07:00
parent bf1970b78c
commit b6d26597c0
2 changed files with 22 additions and 0 deletions

View File

@ -28,6 +28,11 @@ def trigger(hass, config, action):
from_state = config.get(CONF_FROM, MATCH_ALL)
to_state = config.get(CONF_TO) or config.get(CONF_STATE) or MATCH_ALL
if isinstance(from_state, bool) or isinstance(to_state, bool):
logging.getLogger(__name__).error(
'Config error. Surround to/from values with quotes.')
return False
def state_automation_listener(entity, from_s, to_s):
""" Listens for state changes and calls action. """
action()

View File

@ -8,6 +8,7 @@ import unittest
import homeassistant.core as ha
import homeassistant.components.automation as automation
import homeassistant.components.automation.state as state
class TestAutomationState(unittest.TestCase):
@ -334,3 +335,19 @@ class TestAutomationState(unittest.TestCase):
self.hass.pool.block_till_done()
self.assertEqual(1, len(self.calls))
def test_if_fails_setup_if_to_boolean_value(self):
self.assertFalse(state.trigger(
self.hass, {
'platform': 'state',
'entity_id': 'test.entity',
'to': True,
}, lambda x: x))
def test_if_fails_setup_if_from_boolean_value(self):
self.assertFalse(state.trigger(
self.hass, {
'platform': 'state',
'entity_id': 'test.entity',
'from': True,
}, lambda x: x))