Add is_state_attr method.

Returns True if the entity exists and has an attribute with the given
name and value.
This commit is contained in:
Andrew Thigpen 2015-12-31 14:58:18 -06:00
parent 326e26fbeb
commit 11f32d0500
4 changed files with 29 additions and 1 deletions

View file

@ -468,6 +468,13 @@ class StateMachine(object):
return (entity_id in self._states and
self._states[entity_id].state == state)
def is_state_attr(self, entity_id, name, value):
"""Test if entity exists and has a state attribute set to value."""
entity_id = entity_id.lower()
return (entity_id in self._states and
self._states[entity_id].attributes.get(name, None) == value)
def remove(self, entity_id):
"""Remove the state of an entity.