diff --git a/homeassistant/core.py b/homeassistant/core.py index 320e857ac9e..a467cf28e51 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -648,7 +648,7 @@ class StateMachine(object): Async friendly. """ state_obj = self.get(entity_id) - return state_obj and state_obj.state == state + return state_obj is not None and state_obj.state == state def is_state_attr(self, entity_id, name, value): """Test if entity exists and has a state attribute set to value. @@ -656,7 +656,8 @@ class StateMachine(object): Async friendly. """ state_obj = self.get(entity_id) - return state_obj and state_obj.attributes.get(name, None) == value + return state_obj is not None and \ + state_obj.attributes.get(name, None) == value def remove(self, entity_id): """Remove the state of an entity. diff --git a/tests/helpers/test_template.py b/tests/helpers/test_template.py index b6951172c64..71075124f32 100644 --- a/tests/helpers/test_template.py +++ b/tests/helpers/test_template.py @@ -314,6 +314,11 @@ class TestHelpersTemplate(unittest.TestCase): """, self.hass) self.assertEqual('yes', tpl.render()) + tpl = template.Template(""" +{{ is_state("test.noobject", "available") }} + """, self.hass) + self.assertEqual('False', tpl.render()) + def test_is_state_attr(self): """Test is_state_attr method.""" self.hass.states.set('test.object', 'available', {'mode': 'on'}) @@ -322,6 +327,11 @@ class TestHelpersTemplate(unittest.TestCase): """, self.hass) self.assertEqual('yes', tpl.render()) + tpl = template.Template(""" +{{ is_state_attr("test.noobject", "mode", "on") }} + """, self.hass) + self.assertEqual('False', tpl.render()) + def test_states_function(self): """Test using states as a function.""" self.hass.states.set('test.object', 'available')