Fixed value error exception

Fixed unittest
This commit is contained in:
Stefan Jonasson 2015-09-13 19:59:26 +02:00
parent a2ca60159d
commit e9da02d70c
2 changed files with 5 additions and 6 deletions

View file

@ -40,12 +40,12 @@ def register(hass, config, action):
:return: :return:
""" """
if value is None: try:
value = float(value)
except ValueError:
_LOGGER.warn("Missing value in numeric check") _LOGGER.warn("Missing value in numeric check")
return False return False
value = float(value)
if range_start is not None and range_end is not None: if range_start is not None and range_end is not None:
return float(range_start) <= value < float(range_end) return float(range_start) <= value < float(range_end)
elif range_end is not None: elif range_end is not None:

View file

@ -12,12 +12,11 @@ import homeassistant.components.automation.numeric_state as numeric_state
from homeassistant.const import CONF_PLATFORM from homeassistant.const import CONF_PLATFORM
class TestAutomationState(unittest.TestCase): class TestAutomationNumericState(unittest.TestCase):
""" Test the event automation. """ """ Test the event automation. """
def setUp(self): # pylint: disable=invalid-name def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant() self.hass = ha.HomeAssistant()
self.hass.states.set('test.entity', 'hello')
self.calls = [] self.calls = []
def record_call(service): def record_call(service):
@ -96,7 +95,7 @@ class TestAutomationState(unittest.TestCase):
# 9 is below 10 so this should not fire again # 9 is below 10 so this should not fire again
self.hass.states.set('test.entity', 8) self.hass.states.set('test.entity', 8)
self.hass.pool.block_till_done() 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): def test_if_fires_on_entity_change_above(self):