From 95759e78176cb83dfae2ea2b8bd98dfc80b652ae Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 30 Apr 2024 11:05:29 -0500 Subject: [PATCH] fix: handle missing hci devices when enumerating adapters (#129) --- src/bluetooth_adapters/systems/linux.py | 27 ++++++++++++++++--------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/bluetooth_adapters/systems/linux.py b/src/bluetooth_adapters/systems/linux.py index 5b186a7..223e541 100644 --- a/src/bluetooth_adapters/systems/linux.py +++ b/src/bluetooth_adapters/systems/linux.py @@ -107,20 +107,27 @@ def adapters(self) -> dict[str, AdapterDetails]: or usb_device.manufacturer == "Unknown" ): manufacturer = aiooui.get_vendor(mac_address) - else: + elif usb_device is not None: manufacturer = usb_device.manufacturer - product = usb_device.product - vendor_id = usb_device.vendor_id - product_id = usb_device.product_id + if usb_device is not None: + product = usb_device.product + vendor_id = usb_device.vendor_id + product_id = usb_device.product_id elif isinstance(device, UARTBluetoothDevice): uart_device = device.uart_device - if mac_address == EMPTY_MAC_ADDRESS: - manufacturer = uart_device.manufacturer + if uart_device is None: + if mac_address != EMPTY_MAC_ADDRESS: + manufacturer = aiooui.get_vendor(mac_address) else: - manufacturer = ( - aiooui.get_vendor(mac_address) or uart_device.manufacturer - ) - product = uart_device.product + product = uart_device.product + + if mac_address == EMPTY_MAC_ADDRESS: + manufacturer = uart_device.manufacturer + else: + manufacturer = ( + aiooui.get_vendor(mac_address) + or uart_device.manufacturer + ) adapters[adapter] = AdapterDetails( address=mac_address,