components/batterycontrol: Re-use battery names correctly
Previously, if a battery was seen twice, it would not re-use the existing name, leading to the user seeing a single battery called "Battery 2".
The code has also been re-written to be more intelligible.
Reason for the change
When, for some reason, a battery's name was updated twice, the previous name was not used.
Test plan
The original bug reporter has confirmed that these changes work for them, but that doesn't test battery removal/replug - only that previous names are now remembered.
i.e. it only tests the code path where no batteries are known (m_namedBatteries.isEmpty()
), and where the same battery name is reused (m_namedBatteries.contains(deviceBattery.udi()
), but not trying to use an unused index (i.e. you have batteries 1, 2 and 3, and remove battery 2 and plug a new one in - it should be known as battery 2.)