Skip to content

Commit

Permalink
feat: ignore adapters with a 00:00:00:00:00:00 mac address (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Jan 4, 2024
1 parent 4b14786 commit cdca7b2
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/bluetooth_adapters/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
# Some operating systems hide the adapter address for privacy reasons (ex MacOS)
DEFAULT_ADDRESS: Final = "00:00:00:00:00:00"

EMPTY_MAC_ADDRESS: Final = "00:00:00:00:00:00"

DEFAULT_CONNECTION_SLOTS: Final = 5
8 changes: 6 additions & 2 deletions src/bluetooth_adapters/systems/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from usb_devices import BluetoothDevice, NotAUSBDeviceError

from ..adapters import BluetoothAdapters
from ..const import UNIX_DEFAULT_BLUETOOTH_ADAPTER
from ..const import EMPTY_MAC_ADDRESS, UNIX_DEFAULT_BLUETOOTH_ADAPTER
from ..dbus import BlueZDBusObjects
from ..history import AdvertisementHistory
from ..models import AdapterDetails
Expand Down Expand Up @@ -104,9 +104,13 @@ def adapters(self) -> dict[str, AdapterDetails]:
for adapter, details in adapter_details.items():
if not (adapter1 := details.get("org.bluez.Adapter1")):
continue
mac_address = adapter1["Address"]
if mac_address == EMPTY_MAC_ADDRESS:
# Ignore adapters with 00:00:00:00:00:00 address
# https://github.com/home-assistant/operating-system/issues/2944
continue
device = self._devices[adapter]
usb_device = device.usb_device
mac_address = adapter1["Address"]
if (
usb_device is None
or usb_device.vendor_id == usb_device.manufacturer
Expand Down
102 changes: 101 additions & 1 deletion tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,92 @@ async def connect(self):
"org.freedesktop.DBus.Properties": {},
},
"/org/bluez/hci1": {},
"/org/bluez/hci2": {
"org.bluez.Adapter1": {
"Address": "00:00:00:00:00:00",
"AddressType": "public",
"Alias": "homeassistant",
"Class": 2883584,
"Discoverable": False,
"DiscoverableTimeout": 180,
"Discovering": True,
"Modalias": "usb:v1D6Bp0246d053F",
"Name": "homeassistant",
"Pairable": False,
"PairableTimeout": 0,
"Powered": True,
"Roles": ["central", "peripheral"],
"UUIDs": [
"0000110e-0000-1000-8000-00805f9b34fb",
"0000110a-0000-1000-8000-00805f9b34fb",
"00001200-0000-1000-8000-00805f9b34fb",
"0000110b-0000-1000-8000-00805f9b34fb",
"00001108-0000-1000-8000-00805f9b34fb",
"0000110c-0000-1000-8000-00805f9b34fb",
"00001800-0000-1000-8000-00805f9b34fb",
"00001801-0000-1000-8000-00805f9b34fb",
"0000180a-0000-1000-8000-00805f9b34fb",
"00001112-0000-1000-8000-00805f9b34fb",
],
},
"org.bluez.GattManager1": {},
"org.bluez.LEAdvertisingManager1": {
"ActiveInstances": 0,
"SupportedIncludes": [
"tx-power",
"appearance",
"local-name",
],
"SupportedInstances": 5,
},
"org.bluez.Media1": {},
"org.bluez.NetworkServer1": {},
"org.freedesktop.DBus.Introspectable": {},
"org.freedesktop.DBus.Properties": {},
},
"/org/bluez/hci3": {
"org.bluez.Adapter1": {
"Address": "00:1A:7D:DA:71:05",
"AddressType": "public",
"Alias": "homeassistant",
"Class": 2883584,
"Discoverable": False,
"DiscoverableTimeout": 180,
"Discovering": True,
"Modalias": "usb:v1D6Bp0246d053F",
"Name": "homeassistant",
"Pairable": False,
"PairableTimeout": 0,
"Powered": True,
"Roles": ["central", "peripheral"],
"UUIDs": [
"0000110e-0000-1000-8000-00805f9b34fb",
"0000110a-0000-1000-8000-00805f9b34fb",
"00001200-0000-1000-8000-00805f9b34fb",
"0000110b-0000-1000-8000-00805f9b34fb",
"00001108-0000-1000-8000-00805f9b34fb",
"0000110c-0000-1000-8000-00805f9b34fb",
"00001800-0000-1000-8000-00805f9b34fb",
"00001801-0000-1000-8000-00805f9b34fb",
"0000180a-0000-1000-8000-00805f9b34fb",
"00001112-0000-1000-8000-00805f9b34fb",
],
},
"org.bluez.GattManager1": {},
"org.bluez.LEAdvertisingManager1": {
"ActiveInstances": 0,
"SupportedIncludes": [
"tx-power",
"appearance",
"local-name",
],
"SupportedInstances": 5,
},
"org.bluez.Media1": {},
"org.bluez.NetworkServer1": {},
"org.freedesktop.DBus.Introspectable": {},
"org.freedesktop.DBus.Properties": {},
},
"/org/bluez/hci1/any": {},
"/org/bluez/hci0/dev_54_D2_72_AB_35_95": {
"org.freedesktop.DBus.Introspectable": {},
Expand Down Expand Up @@ -600,16 +686,30 @@ def setup(self, *args, **kwargs):
device=ANY, advertisement_data=ANY, source="hci0"
)
}
# hci0 should show
# hci1 is empty so it should not be in the list
# hci2 should not show because it has a 00:00:00:00:00:00 address
# hci3 should show
assert bluetooth_adapters.adapters == {
"hci0": {
"address": "00:1A:7D:DA:71:04",
"hw_version": "usb:v1D6Bp0246d053F",
"manufacturer": "XTech",
"passive_scan": False,
"product": "Bluetooth 4.0 USB Adapter",
"vendor_id": "0a12",
"product_id": "0001",
"sw_version": "homeassistant",
"vendor_id": "0a12",
},
"hci3": {
"address": "00:1A:7D:DA:71:05",
"hw_version": "usb:v1D6Bp0246d053F",
"manufacturer": "XTech",
"passive_scan": False,
"product": "Bluetooth 4.0 USB Adapter",
"product_id": "0001",
"sw_version": "homeassistant",
"vendor_id": "0a12",
},
}

Expand Down

0 comments on commit cdca7b2

Please sign in to comment.