It has been de jure independent since 1648 (with the exception of a few years of Napoleonic control), and de facto for at least 150 years before that.
And yes, in between there were were several hundred years where Switzerland was part of whatever passed for "France" and "Germany" in those times, but I'm not sure that era was any more fundamental than the rest of history.
Which, together, still make today 50% of all the "foreigners" living in Switzerland.
They are called immigrants, but are actually people with a grandfather who went there 50-60 years ago who never became a regular citizen.
Only 0.1% of the Swiss population are non-naturalized third generation immigrants, and only 2.4% are non-naturalized second generation immigrants. https://www.bfs.admin.ch/bfs/en/home/statistics/population/m...
This is still higher than e.g. in the US, where the corresponding numbers are close to zero, but it's not nearly as high as it used to be.