add timeout exception to _discover_device
This commit is contained in:
1 parent
138e7cf315
commit
d22a26d2dc
1 file changed
+19
-6
+19
-6
@@ -65,13 +65,26 @@ class SensorReading:
|
||||
# --------------------------------------------------------------------------- #
|
||||
async def _discover_device(mac: str) -> Optional[str]:
|
||||
"""Scan once for the given MAC and return its address if found."""
|
||||
devices = await BleakScanner.discover(timeout=SCAN_TIMEOUT)
|
||||
for d in devices:
|
||||
if d.address.lower() == mac.lower():
|
||||
log.info("Found device %s (%s)", d.name or d.address, d.address)
|
||||
return d.address
|
||||
log.warning("Device %s not found in scan", mac)
|
||||
try:
|
||||
devices = await asyncio.wait_for(
|
||||
BleakScanner.discover(timeout=SCAN_TIMEOUT),
|
||||
timeout=SCAN_TIMEOUT + 2.0, # give a small buffer over scan timeout
|
||||
)
|
||||
for d in devices:
|
||||
if d.address.lower() == mac.lower():
|
||||
log.info("Found device %s (%s)", d.name or d.address, d.address)
|
||||
return d.address
|
||||
log.warning("Device %s not found in scan", mac)
|
||||
except asyncio.TimeoutError:
|
||||
log.warning("Discover call timed out after %.1fs for %s", SCAN_TIMEOUT + 2.0, mac)
|
||||
return None
|
||||
|
||||
#for d in devices:
|
||||
# if d.address.lower() == mac.lower():
|
||||
# log.info("Found device %s (%s)", d.name or d.address, d.address)
|
||||
# return d.address
|
||||
#log.warning("Device %s not found in scan", mac)
|
||||
#return None
|
||||
|
||||
|
||||
def _parse_sensor_data(raw: bytes) -> (float, int):
|
||||
|
||||
Reference in new issue
Block a user