DO NOT MERGE - Add validation and warning for modified Shelly device IDs with invalid MAC addresses #1255
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.
Description
This PR implements validation to detect and warn users when Shelly device IDs contain invalid MAC address formats in the serial ID portion. This addresses cases where users have manually modified device IDs with custom names instead of proper MAC addresses.
Problem
Users may modify Shelly device IDs to use custom identifiers (e.g.,
shellyplusuni#regentonne
instead ofshellyplusuni#A4CF12F454A3
). While these modified IDs may work in some cases, they don't follow the standard Shelly device naming convention where the serial portion should be a valid MAC address in hexadecimal format. This can lead to confusion and potential issues.Solution
Added automatic validation that checks device IDs when devices connect via MQTT or CoAP protocols. If an invalid MAC address format is detected, a clear warning is logged:
Implementation Details
Core validation logic (
lib/protocol/base.js
):isValidMacAddress(serialId)
: Validates that serial IDs contain only hexadecimal characters (0-9, A-F, a-f) with minimum 6 character lengthvalidateDeviceId()
: Checks device IDs and logs warnings for invalid formatsIntegration points:
start()
methodNon-breaking change: Only logs warnings; devices continue to function normally
Testing
Added comprehensive test suite with 7 new test cases covering:
All tests passing (18 total: 11 existing + 7 new)
ESLint validation passes with no errors
Examples
Valid device IDs (no warning):
SHBDUO-1#8CAAB5616291#2
SHRGBW2#C45BBE798F0F#1
shellypro2pm#30c6f7850a64#1
Invalid device IDs (warning logged):
shellyplusuni#regentonne#1
(from issue)SHELLY#my-device#1
SHELLY#test123#1
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.