My apologies for the confusion. Duplicates are just ignored. They are not the problem.
The problem occurs when a new launcher_id is assigned to an existing MAC address in the database. In this case, the entries in the data base need to be updated so the new launcher_id is associated with the existing MAC address, and the old launcher_id is removed.
Removing data and adding data to Preferences in the same function seems to be a problem, which is why I think it is a timing issue within the library, or just an artifact of how long it takes the hardware to add data.
In the test cases, this data is added:
saveToPreferences(2, "02:05:04:03:02:01");
At the end of the test cases, this data is added:
saveToPreferences(9, "02:05:04:03:02:01");
Note the MAC addresses are the same, but the first digit, the launcher_id is different. So, I need to update the Preferences so launcher_id=9 has MAC address 02:05:04:03:02:01 associated with it, and launcher_id=2 no longer exists in the database.
Right before the addition of 'launcher_id=9`, Preferences should look like this, based on the test cases:
{1: 01:02:03:04:05:06}, {010203040506: 1}
{3: 03:05:04:03:02:01}, {030504030201: 3}
{2: 02:05:04:03:02:01}, {020504030201: 9}
{8: 08:05:04:03:02:01}, {080504030201: 8}
After the addition of launcher_id=9, Preferences should look like this:
{1: 01:02:03:04:05:06}, {010203040506: 1}
{3: 03:05:04:03:02:01}, {030504030201: 3}
{8: 08:05:04:03:02:01}, {080504030201: 8}
{9: 02:05:04:03:02:01}, {020504030201: 9}
I hope that helps!