mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Automation - state platfor: Flag if user makes config error
This commit is contained in:
parent
bf1970b78c
commit
b6d26597c0
@ -28,6 +28,11 @@ def trigger(hass, config, action):
|
|||||||
from_state = config.get(CONF_FROM, MATCH_ALL)
|
from_state = config.get(CONF_FROM, MATCH_ALL)
|
||||||
to_state = config.get(CONF_TO) or config.get(CONF_STATE) or 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):
|
def state_automation_listener(entity, from_s, to_s):
|
||||||
""" Listens for state changes and calls action. """
|
""" Listens for state changes and calls action. """
|
||||||
action()
|
action()
|
||||||
|
@ -8,6 +8,7 @@ import unittest
|
|||||||
|
|
||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
import homeassistant.components.automation as automation
|
import homeassistant.components.automation as automation
|
||||||
|
import homeassistant.components.automation.state as state
|
||||||
|
|
||||||
|
|
||||||
class TestAutomationState(unittest.TestCase):
|
class TestAutomationState(unittest.TestCase):
|
||||||
@ -334,3 +335,19 @@ class TestAutomationState(unittest.TestCase):
|
|||||||
self.hass.pool.block_till_done()
|
self.hass.pool.block_till_done()
|
||||||
|
|
||||||
self.assertEqual(1, len(self.calls))
|
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))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user