mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +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()
|
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):
|
def get_state(self, category):
|
||||||
""" Returns a dict (state,last_changed, attributes) describing
|
""" Returns a dict (state,last_changed, attributes) describing
|
||||||
the state of the specified category. """
|
the state of the specified category. """
|
||||||
if category not in self.states:
|
if category not in self.states:
|
||||||
raise CategoryDoesNotExistException(
|
return None
|
||||||
"Category {} does not exist.".format(category))
|
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
|
def is_state(self, category, state):
|
||||||
return dict(self.states[category])
|
""" 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):
|
class Timer(threading.Thread):
|
||||||
""" Timer will sent out an event every TIMER_INTERVAL seconds. """
|
""" Timer will sent out an event every TIMER_INTERVAL seconds. """
|
||||||
@ -293,7 +290,4 @@ class Timer(threading.Thread):
|
|||||||
class HomeAssistantException(Exception):
|
class HomeAssistantException(Exception):
|
||||||
""" General Home Assistant exception occured. """
|
""" 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