New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Normalize MAC addresses #16916
Normalize MAC addresses #16916
Conversation
lower_mac = mac.lower() | ||
if len(lower_mac) == 12: | ||
# no : included | ||
return ':'.join(lower_mac[i:i + 2] for i in range(0, 12, 2)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to strip everything but hexadecimal values from the Mac? There are multiple standards to format the Mac. Also since if one implementation modifies its Mac to follow its own standard the smallest common denominator should be used to map between components. Or specify what format the Mac needs to be in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are normalizing the value here to lowercase and separated by :
. If an integration sends us any other format, it will be reformatted to ours, so no need to stick to a common denominator because we specify the common one :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It only normalise Mac that doesn't have any ':' but doesn't cover Mac that uses '.' or '-' as separators, see https://en.wikipedia.org/wiki/MAC_address
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I'll strip out any non hexadecimal value and then format it with :
?
d925068
to
c302934
Compare
Updated PR to handle all notional conventions |
Description:
Normalize incoming mac addresses for the device registry.
CC @Kane610
Checklist:
tox
. Your PR cannot be merged unless tests passIf the code does not interact with devices: