Skip to content

Commit 63c60d4

Browse files
authored
Merge pull request #229 from mkinney/check_for_multiple_mac_conversions
suggested fix from MitchConner912 for not converting mac address more…
2 parents 1410448 + 6a2a9d2 commit 63c60d4

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

meshtastic/tests/test_util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,4 +249,5 @@ def test_findPorts_when_none_found(patch_comports):
249249
def test_convert_mac_addr():
250250
"""Test convert_mac_addr()"""
251251
assert convert_mac_addr('/c0gFyhb') == 'fd:cd:20:17:28:5b'
252+
assert convert_mac_addr('fd:cd:20:17:28:5b') == 'fd:cd:20:17:28:5b'
252253
assert convert_mac_addr('') == ''

meshtastic/util.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import traceback
44
from queue import Queue
55
import os
6+
import re
67
import sys
78
import base64
89
import time
@@ -238,5 +239,7 @@ def convert_mac_addr(val):
238239
val - base64 encoded value (ex: '/c0gFyhb'))
239240
returns: a string formatted like a mac address (ex: 'fd:cd:20:17:28:5b')
240241
"""
241-
val_as_bytes = base64.b64decode(val)
242-
return hexstr(val_as_bytes)
242+
if not re.match("[0-9a-f]{2}([-:]?)[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$", val):
243+
val_as_bytes = base64.b64decode(val)
244+
return hexstr(val_as_bytes)
245+
return val

0 commit comments

Comments
 (0)