add another timeout check on read_data

This commit is contained in:
matt committed 2026-10-16 00:13:07 -07:00
1 parent 3a35f93791
commit 9c63de343a
1 file changed
+15 -1
+15 -1
View File
@@ -38,6 +38,7 @@ SCAN_TIMEOUT = 10.0 # seconds to scan for each MAC
CONNECT_TIMEOUT = 20.0
READ_TIMEOUT = 5.0
SERVICE_DISCOVERY_TIMEOUT = 10.0
DISCOVER_TIMEOUT = SCAN_TIMEOUT + 5.0 # Timeout for discovering device
# --------------------------------------------------------------------------- #
# Logging
@@ -138,10 +139,23 @@ def scan_macs():
# Core async read functions (unchanged from the refactored version)
# --------------------------------------------------------------------------- #
async def read_data(mac: str) -> Optional[SensorReading]:
address = await _discover_device(mac)
try:
address = await asyncio.wait_for(
_discover_device(mac),
timeout=DISCOVER_TIMEOUT,
)
except asyncio.TimeoutError:
log.warning("Device discovery timed out for %s after %.1fs", mac, DISCOVER_TIMEOUT)
return None
if not address:
return None
#address = await _discover_device(mac)
#if not address:
# return None
try:
async with BleakClient(address, timeout=CONNECT_TIMEOUT) as client:
# <--- NEW BLOCK ----------------------------------------------