From 1da1713d2f023716a0bf7f73c85d30ba4b48da7e Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sat, 26 Oct 2013 22:26:58 +0100 Subject: [PATCH] StateMachine.is_state will return False if category does not exist --- homeassistant/__init__.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/homeassistant/__init__.py b/homeassistant/__init__.py index d7285671074..b38eaddcd30 100644 --- a/homeassistant/__init__.py +++ b/homeassistant/__init__.py @@ -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. """