'Test getting states at a specific point in time.'

def test_get_states(self):

    self.init_recorder()
    states = []
    now = dt_util.utcnow()
    with patch('homeassistant.components.recorder.dt_util.utcnow', return_value=now):
        for i in range(5):
            state = ha.State('test.point_in_time_{}'.format((i % 5)), 'State    {}'.format(i), {'attribute_test': i})
            mock_state_change_event(self.hass, state)
            states.append(state)
        self.wait_recording_done()
    future = (now + timedelta(seconds=1))
    with patch('homeassistant.components.recorder.dt_util.utcnow', return_value=future):
        for i in range(5):
            state = ha.State('test.point_in_time_{}'.format((i % 5)), 'State    {}'.format(i), {'attribute_test': i})
            mock_state_change_event(self.hass, state)
        self.wait_recording_done()
    self.assertEqual(states, sorted(history.get_states(self.hass, future), key=(lambda state: state.entity_id)))
    self.assertEqual(states[0], history.get_state(self.hass, future, states[0].entity_id))
