Add and restore context in recorder (#15859)
This commit is contained in:
1 parent
da916d7b27
commit
9512bb9587
7 files changed
+73
-14
No files matched your search
+1
-1
@@ -266,7 +266,7 @@ def mock_state_change_event(hass, new_state, old_state=None):
|
||||
if old_state:
|
||||
event_data['old_state'] = old_state
|
||||
|
||||
hass.bus.fire(EVENT_STATE_CHANGED, event_data)
|
||||
hass.bus.fire(EVENT_STATE_CHANGED, event_data, context=new_state.context)
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
|
||||
@@ -60,7 +60,7 @@ class TestStates(unittest.TestCase):
|
||||
'entity_id': 'sensor.temperature',
|
||||
'old_state': None,
|
||||
'new_state': state,
|
||||
})
|
||||
}, context=state.context)
|
||||
assert state == States.from_event(event).to_native()
|
||||
|
||||
def test_from_event_to_delete_state(self):
|
||||
|
||||
@@ -83,9 +83,10 @@ class TestComponentHistory(unittest.TestCase):
|
||||
self.wait_recording_done()
|
||||
|
||||
# Get states returns everything before POINT
|
||||
self.assertEqual(states,
|
||||
sorted(history.get_states(self.hass, future),
|
||||
key=lambda state: state.entity_id))
|
||||
for state1, state2 in zip(
|
||||
states, sorted(history.get_states(self.hass, future),
|
||||
key=lambda state: state.entity_id)):
|
||||
assert state1 == state2
|
||||
|
||||
# Test get_state here because we have a DB setup
|
||||
self.assertEqual(
|
||||
|
||||
+2
-1
@@ -246,8 +246,9 @@ class TestEvent(unittest.TestCase):
|
||||
"""Test events."""
|
||||
now = dt_util.utcnow()
|
||||
data = {'some': 'attr'}
|
||||
context = ha.Context()
|
||||
event1, event2 = [
|
||||
ha.Event('some_type', data, time_fired=now)
|
||||
ha.Event('some_type', data, time_fired=now, context=context)
|
||||
for _ in range(2)
|
||||
]
|
||||
|
||||
|
||||
Reference in new issue
Block a user