Scan always at least for 10 seconds before failing on `get_device`.

This commit is contained in:
Fabio Manganiello 2023-03-23 17:41:37 +01:00
parent 6267943786
commit 43289a3b55
Signed by: blacklight
GPG Key ID: D90FBA7F76362774
1 changed files with 10 additions and 1 deletions

View File

@ -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}"'