at master 2.7 kB view raw
1diff --git a/pyzerproc/discovery.py b/pyzerproc/discovery.py 2index e383996..1810bbe 100644 3--- a/pyzerproc/discovery.py 4+++ b/pyzerproc/discovery.py 5@@ -4,6 +4,9 @@ import logging 6 from .light import Light 7 from .exceptions import ZerprocException 8 9+from bleak import BLEDevice, BleakScanner, AdvertisementData 10+from bleak.exc import BleakError 11+ 12 _LOGGER = logging.getLogger(__name__) 13 14 EXPECTED_SERVICES = [ 15@@ -13,27 +16,25 @@ EXPECTED_SERVICES = [ 16 ] 17 18 19-def is_valid_device(device): 20+def is_valid_device(device: BLEDevice, advertisement_data: AdvertisementData): 21 """Returns true if the given device is a Zerproc light.""" 22 for service in EXPECTED_SERVICES: 23- if service not in device.metadata['uuids']: 24+ if service not in advertisement_data.service_uuids: 25 return False 26 return True 27 28 29 async def discover(timeout=10): 30 """Returns nearby discovered lights.""" 31- import bleak 32- 33 _LOGGER.info("Starting scan for local devices") 34 35 lights = [] 36 try: 37- devices = await bleak.BleakScanner.discover(timeout=timeout) 38- except bleak.exc.BleakError as ex: 39+ devices = await BleakScanner.discover(timeout=timeout, return_adv=True) 40+ except BleakError as ex: 41 raise ZerprocException() from ex 42- for device in devices: 43- if is_valid_device(device): 44+ for device, advertisement_data in devices: 45+ if is_valid_device(device, advertisement_data): 46 lights.append(Light(device.address, device.name)) 47 48 _LOGGER.info("Scan complete") 49diff --git a/tests/test_discovery.py b/tests/test_discovery.py 50index 7a1442d..6b271b8 100644 51--- a/tests/test_discovery.py 52+++ b/tests/test_discovery.py 53@@ -16,7 +16,6 @@ async def test_discover_devices(scanner, client_class): 54 'AA:BB:CC:11:22:33', 55 'LEDBlue-CC112233', 56 {}, 57- 0, 58 uuids=[ 59 "0000ffe0-0000-1000-8000-00805f9b34fb", 60 "0000ffe5-0000-1000-8000-00805f9b34fb", 61@@ -27,7 +26,6 @@ async def test_discover_devices(scanner, client_class): 62 'AA:BB:CC:44:55:66', 63 'LEDBlue-CC445566', 64 {}, 65- 0, 66 uuids=[ 67 "0000ffe0-0000-1000-8000-00805f9b34fb", 68 "0000ffe5-0000-1000-8000-00805f9b34fb", 69@@ -38,7 +36,6 @@ async def test_discover_devices(scanner, client_class): 70 'DD:EE:FF:11:22:33', 71 'Other', 72 {}, 73- 0, 74 uuids=[ 75 "0000fe9f-0000-1000-8000-00805f9b34fb", 76 ],