Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 3, 2025

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 of shellyplusuni#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:

[WARN] Device ID "shellyplusuni#regentonne#1" contains an invalid MAC address format in serial part "regentonne". 
Expected hexadecimal characters (0-9, A-F) but found other characters. 
This may indicate a manually modified device ID which could cause issues.

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 length
    • validateDeviceId(): Checks device IDs and logs warnings for invalid formats
  • Integration points:

    • CoAP protocol: Validation runs during device initialization in start() method
    • MQTT protocol: Validation runs after successful authentication in connection handler
  • Non-breaking change: Only logs warnings; devices continue to function normally

Testing

  • Added comprehensive test suite with 7 new test cases covering:

    • Valid MAC address formats (various lengths, mixed case)
    • Invalid formats (non-hex characters, custom names)
    • Edge cases (empty, null, undefined, too short)
    • Warning log verification
  • 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

This section details on the original issue you should resolve

<issue_title>[Enhancement]: Log Warning if shelly-id modified</issue_title>
<issue_description>### I'm sure that

  • This issue is still present in the current beta version of this adapter
  • There is no other (open) issue with the same topic (use the search!)
  • This issue is not described in the adapter documentation / FAQ (read the docs!)

Shelly device

gen1+

Protocol

MQTT

The suggestion

Adapter should check if ID is obviously modified. Whenerver the format does not match the standard, wa warning should be issued, i.e. shellyplusuni#regentonne - no valid MAC as second part

Version of adapter

n/a</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #1215

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

- Added isValidMacAddress() method to validate serial ID format
- Added validateDeviceId() method to log warning for invalid MACs
- Integrated validation in MQTT and CoAP client initialization
- Added comprehensive tests for validation functionality
- Addresses issue where modified device IDs like "shellyplusuni#regentonne" now trigger warnings

Co-authored-by: GermanBluefox <[email protected]>
@Copilot Copilot AI changed the title [WIP] [Enhancement]: Log Warning if shelly-id modified Add validation and warning for modified Shelly device IDs with invalid MAC addresses Oct 3, 2025
@Copilot Copilot AI requested a review from GermanBluefox October 3, 2025 11:10
Copilot finished work on behalf of GermanBluefox October 3, 2025 11:10
@mcm1957 mcm1957 requested review from mcm1957 and removed request for GermanBluefox October 3, 2025 15:00
@mcm1957
Copy link
Member

mcm1957 commented Oct 3, 2025

Look like there has been much more code added / change sthan to require the check at mqtt.
No changes at coap are requried by issue at .

ON HOLD _ DO NOT MERGE

@mcm1957 mcm1957 changed the title Add validation and warning for modified Shelly device IDs with invalid MAC addresses DO NOT MERGE - Add validation and warning for modified Shelly device IDs with invalid MAC addresses Oct 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement]: Log Warning if shelly-id modified
3 participants