Skip to content

Commit 55ffc10

Browse files
authored
Fix BLE mac address parsing (#988)
1 parent d2c6357 commit 55ffc10

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

aioshelly/ble/manufacturer_data.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ def parse_shelly_manufacturer_data(
5858
offset += 2
5959

6060
elif block_type == BLOCK_TYPE_MAC:
61-
# 6 bytes MAC address
61+
# 6 bytes MAC address (stored in reverse order)
6262
if offset + 6 > len(data):
6363
break
6464
mac_bytes = data[offset : offset + 6]
65-
# Format as standard MAC address
66-
result["mac"] = ":".join(f"{b:02X}" for b in mac_bytes)
65+
# Format as standard MAC address (reverse the byte order)
66+
result["mac"] = ":".join(f"{b:02X}" for b in reversed(mac_bytes))
6767
offset += 6
6868

6969
elif block_type == BLOCK_TYPE_MODEL:

tests/ble/test_manufacturer_data.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ def test_parse_flags_only() -> None:
3737

3838
def test_parse_mac_only() -> None:
3939
"""Test parsing manufacturer data with MAC address only."""
40-
# Block type 0x0A (MAC) + 6 bytes MAC address
40+
# Block type 0x0A (MAC) + 6 bytes MAC address (stored in reverse order)
4141
data = bytes([BLOCK_TYPE_MAC, 0xC0, 0x49, 0xEF, 0x88, 0x73, 0xE8])
4242
result = parse_shelly_manufacturer_data({ALLTERCO_MFID: data})
43-
assert result == {"mac": "C0:49:EF:88:73:E8"}
43+
# MAC bytes are reversed when parsed
44+
assert result == {"mac": "E8:73:88:EF:49:C0"}
4445

4546

4647
def test_parse_model_only() -> None:
@@ -65,7 +66,7 @@ def test_parse_all_blocks() -> None:
6566
0xEF,
6667
0x88,
6768
0x73,
68-
0xE8, # MAC
69+
0xE8, # MAC (stored in reverse order)
6970
BLOCK_TYPE_MODEL,
7071
0x34,
7172
0x12, # model = 0x1234
@@ -74,7 +75,7 @@ def test_parse_all_blocks() -> None:
7475
result = parse_shelly_manufacturer_data({ALLTERCO_MFID: data})
7576
assert result == {
7677
"flags": 0x0007,
77-
"mac": "C0:49:EF:88:73:E8",
78+
"mac": "E8:73:88:EF:49:C0", # MAC bytes are reversed when parsed
7879
"model_id": 0x1234,
7980
}
8081

0 commit comments

Comments
 (0)