From 43289a3b551f28bcea336de5d3154c9d12e2ef8e Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 23 Mar 2023 17:41:37 +0100 Subject: [PATCH] Scan always at least for 10 seconds before failing on `get_device`. --- platypush/plugins/bluetooth/_ble/_manager.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/platypush/plugins/bluetooth/_ble/_manager.py b/platypush/plugins/bluetooth/_ble/_manager.py index 1637cfbde..99d043133 100644 --- a/platypush/plugins/bluetooth/_ble/_manager.py +++ b/platypush/plugins/bluetooth/_ble/_manager.py @@ -42,6 +42,12 @@ class BLEManager(BaseBluetoothManager): RSSI update, in seconds. """ + _min_get_device_scan_duration: Final[int] = 10 + """ + Wait at least this many seconds for a device to be discovered when calling + get_device(). + """ + def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) @@ -74,7 +80,10 @@ class BLEManager(BaseBluetoothManager): dev = self._device_cache.get(device) if not dev: self.logger.info('Scanning for unknown device "%s"', device) - await self._scan() + await self._scan( + duration=max(self._min_get_device_scan_duration, self.poll_interval) + ) + dev = self._device_cache.get(device) assert dev, f'Unknown device: "{device}"'