···
1
+
diff --git a/pyzerproc/discovery.py b/pyzerproc/discovery.py
2
+
index 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
9
+
+from bleak import BLEDevice, BleakScanner, AdvertisementData
10
+
+from bleak.exc import BleakError
12
+
_LOGGER = logging.getLogger(__name__)
14
+
EXPECTED_SERVICES = [
15
+
@@ -13,27 +16,25 @@ EXPECTED_SERVICES = [
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:
29
+
async def discover(timeout=10):
30
+
"""Returns nearby discovered lights."""
33
+
_LOGGER.info("Starting scan for local devices")
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))
48
+
_LOGGER.info("Scan complete")
49
+
diff --git a/tests/test_discovery.py b/tests/test_discovery.py
50
+
index 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',
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',
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',
75
+
"0000fe9f-0000-1000-8000-00805f9b34fb",