|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | | -from aioesphomeapi.core import MESSAGE_TYPE_TO_PROTO |
| 3 | +import pytest |
| 4 | + |
| 5 | +from aioesphomeapi.core import MESSAGE_TYPE_TO_PROTO, wifi_mac_to_bluetooth_mac |
4 | 6 |
|
5 | 7 |
|
6 | 8 | def test_order_and_no_missing_numbers_in_message_type_to_proto(): |
7 | 9 | """Test that MESSAGE_TYPE_TO_PROTO has no missing numbers.""" |
8 | 10 | for idx, (k, v) in enumerate(MESSAGE_TYPE_TO_PROTO.items()): |
9 | 11 | assert idx + 1 == k |
| 12 | + |
| 13 | + |
| 14 | +def test_wifi_mac_to_bluetooth_mac(): |
| 15 | + """Test converting WiFi MAC address to Bluetooth MAC address.""" |
| 16 | + # Test with uppercase MAC without colons |
| 17 | + assert wifi_mac_to_bluetooth_mac("AABBCCDDEEFF") == "AA:BB:CC:DD:EE:01" |
| 18 | + |
| 19 | + # Test with lowercase MAC with colons |
| 20 | + assert wifi_mac_to_bluetooth_mac("aa:bb:cc:dd:ee:ff") == "AA:BB:CC:DD:EE:01" |
| 21 | + |
| 22 | + # Test with uppercase MAC with colons |
| 23 | + assert wifi_mac_to_bluetooth_mac("AA:BB:CC:DD:EE:FF") == "AA:BB:CC:DD:EE:01" |
| 24 | + |
| 25 | + # Test with mixed case |
| 26 | + assert wifi_mac_to_bluetooth_mac("Aa:Bb:Cc:Dd:Ee:Ff") == "AA:BB:CC:DD:EE:01" |
| 27 | + |
| 28 | + # Test rollover (FE + 2 = 00, wraps around) |
| 29 | + assert wifi_mac_to_bluetooth_mac("AA:BB:CC:DD:EE:FE") == "AA:BB:CC:DD:EE:00" |
| 30 | + |
| 31 | + # Test edge case with FF (FF + 2 = 01, wraps around) |
| 32 | + assert wifi_mac_to_bluetooth_mac("AA:BB:CC:DD:EE:FF") == "AA:BB:CC:DD:EE:01" |
| 33 | + |
| 34 | + # Test with 00 |
| 35 | + assert wifi_mac_to_bluetooth_mac("AA:BB:CC:DD:EE:00") == "AA:BB:CC:DD:EE:02" |
| 36 | + |
| 37 | + # Test with FD (FD + 2 = FF) |
| 38 | + assert wifi_mac_to_bluetooth_mac("AA:BB:CC:DD:EE:FD") == "AA:BB:CC:DD:EE:FF" |
| 39 | + |
| 40 | + |
| 41 | +def test_wifi_mac_to_bluetooth_mac_invalid(): |
| 42 | + """Test wifi_mac_to_bluetooth_mac with invalid inputs.""" |
| 43 | + # Test with invalid length |
| 44 | + with pytest.raises(ValueError, match="Invalid MAC address format"): |
| 45 | + wifi_mac_to_bluetooth_mac("AA:BB:CC:DD:EE") |
| 46 | + |
| 47 | + # Test with invalid characters |
| 48 | + with pytest.raises(ValueError, match="Invalid MAC address format"): |
| 49 | + wifi_mac_to_bluetooth_mac("GG:BB:CC:DD:EE:FF") |
| 50 | + |
| 51 | + # Test with completely invalid input |
| 52 | + with pytest.raises(ValueError, match="Invalid MAC address format"): |
| 53 | + wifi_mac_to_bluetooth_mac("not a mac address") |
0 commit comments