feat: Add uppercase option for unique IDs from byte arrays #297
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This pull request introduces the ability for users to generate uppercase hexadecimal unique IDs when creating a device ID from a byte array (such as a MAC address).
The motivation for this change comes from my own usage. I have several existing Arduino sensors that use this library where the unique ID was manually set as an uppercase string from the MAC address. To maintain consistency and keep years of historical data in Home Assistant, I could not switch to the more convenient
setUniqueId(byte[] mac, ...)function because it only produces lowercase output.This change adds a non-breaking option to generate uppercase output, providing more flexibility for both new and existing users who require a specific format.
Changes Made
To achieve this while maintaining full backward compatibility, the following changes were implemented:
HAUtils::byteArrayToStr: Overloaded the function to accept an optionalbool uppercaseparameter. The original function now calls this new overload withfalseto ensure existing behavior is unchanged.HADevice::setUniqueId: Similarly, overloaded the function to accept an optionalbool uppercaseparameter, exposing the new functionality to the end-user.CHANGELOG.mdfor this new feature.Contributor Checklist
CHANGELOG.md.This enhancement is fully tested and documented. I look forward to your feedback!