StateMachine.is_state will return False if category does not exist

This commit is contained in:
Paulus Schoutsen 2013-10-26 22:26:58 +01:00
parent 5374ff7f71
commit 1da1713d2f

View File

@ -215,24 +215,22 @@ class StateMachine(object):
self.lock.release()
def is_state(self, category, state):
""" Returns True if category is specified state. """
""" Returns True if category exists and is specified state. """
return self.get_state(category).state == state
state = self.states.get(category, None)
return state and state.state == state
def get_state(self, category):
""" Returns a tuple (state,last_changed) describing
the state of the specified category. """
self._validate_category(category)
return self.states[category]
def _validate_category(self, category):
""" Helper function to throw an exception
when the category does not exist. """
if category not in self.states:
raise CategoryDoesNotExistException(
"Category {} does not exist.".format(category))
return self.states[category]
class Timer(threading.Thread):
""" Timer will sent out an event every TIMER_INTERVAL seconds. """