From e9da02d70cf7c41fcef2b47bf21aaeea74337979 Mon Sep 17 00:00:00 2001 From: Stefan Jonasson Date: Sun, 13 Sep 2015 19:59:26 +0200 Subject: [PATCH] Fixed value error exception Fixed unittest --- homeassistant/components/automation/numeric_state.py | 6 +++--- tests/components/automation/test_numeric_state.py | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/automation/numeric_state.py b/homeassistant/components/automation/numeric_state.py index b07599390e1..24c9f9db14a 100644 --- a/homeassistant/components/automation/numeric_state.py +++ b/homeassistant/components/automation/numeric_state.py @@ -40,12 +40,12 @@ def register(hass, config, action): :return: """ - if value is None: + try: + value = float(value) + except ValueError: _LOGGER.warn("Missing value in numeric check") return False - value = float(value) - if range_start is not None and range_end is not None: return float(range_start) <= value < float(range_end) elif range_end is not None: diff --git a/tests/components/automation/test_numeric_state.py b/tests/components/automation/test_numeric_state.py index f923c299e51..0b3a0bfba63 100644 --- a/tests/components/automation/test_numeric_state.py +++ b/tests/components/automation/test_numeric_state.py @@ -12,12 +12,11 @@ import homeassistant.components.automation.numeric_state as numeric_state from homeassistant.const import CONF_PLATFORM -class TestAutomationState(unittest.TestCase): +class TestAutomationNumericState(unittest.TestCase): """ Test the event automation. """ def setUp(self): # pylint: disable=invalid-name self.hass = ha.HomeAssistant() - self.hass.states.set('test.entity', 'hello') self.calls = [] def record_call(service): @@ -96,7 +95,7 @@ class TestAutomationState(unittest.TestCase): # 9 is below 10 so this should not fire again self.hass.states.set('test.entity', 8) self.hass.pool.block_till_done() - self.assertEqual(1, len(self.calls)) + self.assertEqual(0, len(self.calls)) def test_if_fires_on_entity_change_above(self):