def test_async_track_states(event_loop):
 hass = get_test_home_assistant()
 try:
  point1 = dt_util.utcnow()
  point2 = (point1 + timedelta(seconds=5))
  point3 = (point2 + timedelta(seconds=5))
  @asyncio.coroutine
  @patch('homeassistant.core.dt_util.utcnow')
  def run_test(mock_utcnow):
   'Run the test.'
   mock_utcnow.return_value = point2
   with state.AsyncTrackStates(hass) as states:
    mock_utcnow.return_value = point1
    hass.states.set('light.test', 'on')
    mock_utcnow.return_value = point2
    hass.states.set('light.test2', 'on')
    state2 = hass.states.get('light.test2')
    mock_utcnow.return_value = point3
    hass.states.set('light.test3', 'on')
    state3 = hass.states.get('light.test3')
   assert ([state2, state3] == sorted(states, key=(lambda state: state.entity_id)))
  event_loop.run_until_complete(run_test())
 finally:
  hass.stop()

def test_async_track_states ( event_loop ) : hass = get_test_home_assistant ( ) try : point1 = dt_util . utcnow ( ) point2 = ( point1 + timedelta ( seconds = 5 ) ) point3 = ( point2 + timedelta ( seconds = 5 ) ) @ asyncio . coroutine @ patch ( 'homeassistant.core.dt_util.utcnow' ) def run_test ( mock_utcnow ) : mock_utcnow . return_value = point2 with state . AsyncTrackStates ( hass ) as states : mock_utcnow . return_value = point1 hass . states . set ( 'light.test' , 'on' ) mock_utcnow . return_value = point2 hass . states . set ( 'light.test2' , 'on' ) state2 = hass . states . get ( 'light.test2' ) mock_utcnow . return_value = point3 hass . states . set ( 'light.test3' , 'on' ) state3 = hass . states . get ( 'light.test3' ) assert ( [ state2 , state3 ] == sorted ( states , key = ( lambda state : state . entity_id ) ) ) event_loop . run_until_complete ( run_test ( ) ) finally : hass . stop ( )
test asynctrackstates context manager .