mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
StateMachine.get_state will not throw an exception but return None if category does not exist
This commit is contained in:
parent
47d2c04c90
commit
24b317f10d
@ -231,23 +231,20 @@ class StateMachine(object):
|
||||
|
||||
self.lock.release()
|
||||
|
||||
def is_state(self, category, state):
|
||||
""" Returns True if category exists and is specified state. """
|
||||
|
||||
cur_state = self.states.get(category, None)
|
||||
|
||||
return cur_state and cur_state['state'] == state
|
||||
|
||||
def get_state(self, category):
|
||||
""" Returns a dict (state,last_changed, attributes) describing
|
||||
the state of the specified category. """
|
||||
if category not in self.states:
|
||||
raise CategoryDoesNotExistException(
|
||||
"Category {} does not exist.".format(category))
|
||||
return None
|
||||
else:
|
||||
# Make a copy so people won't accidently mutate the state
|
||||
return dict(self.states[category])
|
||||
|
||||
# Make a copy so people won't accidently mutate the state
|
||||
return dict(self.states[category])
|
||||
def is_state(self, category, state):
|
||||
""" Returns True if category exists and is specified state. """
|
||||
cur_state = self.get_state(category)
|
||||
|
||||
return cur_state and cur_state['state'] == state
|
||||
|
||||
class Timer(threading.Thread):
|
||||
""" Timer will sent out an event every TIMER_INTERVAL seconds. """
|
||||
@ -293,7 +290,4 @@ class Timer(threading.Thread):
|
||||
class HomeAssistantException(Exception):
|
||||
""" General Home Assistant exception occured. """
|
||||
|
||||
class CategoryDoesNotExistException(HomeAssistantException):
|
||||
""" Specified category does not exist within the state machine. """
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user