Fire event when we remove a state
This commit is contained in:
parent
e170484f16
commit
ada2fb4ec0
4 changed files with 67 additions and 23 deletions
|
@ -438,7 +438,20 @@ class StateMachine(object):
|
|||
entity_id = entity_id.lower()
|
||||
|
||||
with self._lock:
|
||||
return self._states.pop(entity_id, None) is not None
|
||||
old_state = self._states.pop(entity_id, None)
|
||||
|
||||
if old_state is None:
|
||||
return False
|
||||
|
||||
event_data = {
|
||||
'entity_id': entity_id,
|
||||
'old_state': old_state,
|
||||
'new_state': None,
|
||||
}
|
||||
|
||||
self._bus.fire(EVENT_STATE_CHANGED, event_data)
|
||||
|
||||
return True
|
||||
|
||||
def set(self, entity_id, new_state, attributes=None):
|
||||
"""Set the state of an entity, add entity if it does not exist.
|
||||
|
@ -468,10 +481,11 @@ class StateMachine(object):
|
|||
state = State(entity_id, new_state, attributes, last_changed)
|
||||
self._states[entity_id] = state
|
||||
|
||||
event_data = {'entity_id': entity_id, 'new_state': state}
|
||||
|
||||
if old_state:
|
||||
event_data['old_state'] = old_state
|
||||
event_data = {
|
||||
'entity_id': entity_id,
|
||||
'old_state': old_state,
|
||||
'new_state': state,
|
||||
}
|
||||
|
||||
self._bus.fire(EVENT_STATE_CHANGED, event_data)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue